Boost logo

Boost Users :

From: Robert Mecklenburg (rmecklenburg_at_[hidden])
Date: 2006-12-18 17:03:08


I've just upgraded my compiler to gcc 4.1.2 and tried the latest
implementation of tr1 included with gcc. I've discovered the gcc
array implementation is not what I expect:

    #include <boost/array.hpp>
    #include <tr1/array>
    #include <iostream>

    int main(int , char **)
    {
        boost::array<char, 6> barray;
        std::cout << sizeof(barray) << std::endl;

        std::tr1::array<char, 6> tr1array;
        std::cout << sizeof(tr1array) << std::endl;
    }

When run this code produces:

    g++ foo.cpp && ./a.out
    6
    16

That is, the boost array is exactly the size I require 6 bytes, but
the tr1 array is larger, 16 bytes. I believe this is due to the
following declaration in 4.1.2/tr1/array:

      // Support for zero-sized arrays mandatory.
      value_type _M_instance[_Nm ? _Nm : 1] __attribute__((__aligned__));

The boost version is not aligned, but the gcc version is. Does the
tr1 implementation require the alignment? If so, it appears that
tr1::array is definitely not a suitable wrapper for C-style arrays
since they aren't the same size!

What's the scoop?

Thanks,

--
Robert

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net