Boost logo

Boost :

From: Michael van der Westhuizen (Michael.vanderWesthuizen_at_[hidden])
Date: 2003-09-25 03:17:41


mmm... ok, but you can't rely on that:

This is gcc 3.3.1 on HP-UX 11.00.

[michael_at_hippo sizeof-alignment.cpp]$ g++ -O2 main.cpp -o test
[michael_at_hippo sizeof-alignment.cpp]$ ./test
natural: 10l
     2 : 10l
     4 : 10l
     8 : 10l
    16 : 10l
    32 : 10l

This is gcc 3.3 on Tru64 4.0.g

[michael_at_anaconda sizeof-alignment.cpp]$ g++ -threads -O2 main.cpp -o test
-lpthread
main.cpp:57: warning: alignment must be a small power of two, not 32
[michael_at_anaconda sizeof-alignment.cpp]$ ./test
natural: 10l
     2 : 10l
     4 : 10l
     8 : 10l
    16 : 10l
    32 : 10l

This is gcc 3.3 on SunOS 5.8

[michael_at_eagle sizeof-alignment.cpp]$ g++ -O2 main.cpp -o test
main.cpp:57: warning: alignment must be a small power of two, not 32
[michael_at_eagle sizeof-alignment.cpp]$ ./test
natural: 10l
     2 : 10l
     4 : 10l
     8 : 10l
    16 : 10l
    32 : 10l

This is gcc 3.2 (prerelease) on Win2k (Cygwin):

vdwesthuizenm_at_intec-mcvdw /cygdrive/r/not_current/tests/sizeof-alignment.cpp
$ g++ -O2 main.cpp -o test
main.cpp:57: warning: alignment must be a small power of two, not 32

vdwesthuizenm_at_intec-mcvdw /cygdrive/r/not_current/tests/sizeof-alignment.cpp
$ ./test.exe
natural: 10l
     2 : 10l
     4 : 10l
     8 : 10l
    16 : 10l
    32 : 10l

And finally, Visual C++ 7.1:

R:\not_current\tests\sizeof-alignment.cpp>cl /O2 main.cpp /Fetest.exe
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

main.cpp
main.cpp(57) : warning C4086: expected pragma parameter to be '1', '2', '4',
'8'
, or '16'
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
main.obj

R:\not_current\tests\sizeof-alignment.cpp>test
natural: 10l
     2 : 10l
     4 : 10l
     8 : 10l
    16 : 10l
    32 : 10l

It seems that alignment does not affect sizeof.

(and no, I didn't write these tests now: I got the same
 question in a code-review recently)

Michael

-----Original Message-----
From: Rozental, Gennadiy [mailto:gennadiy.rozental_at_[hidden]]
Sent: 24 September 2003 10:38
To: 'Boost mailing list'
Subject: RE: [boost] Re: [ANN] State of Boost.Variant

Probably not. Because of the allignment.

struct A {
int a;
char b;
};

sizeof(A) = 8

Gennadiy

> -----Original Message-----
> From: Bohdan [mailto:gejrlaug_at_[hidden]]
> Sent: Wednesday, September 24, 2003 5:36 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: [ANN] State of Boost.Variant
>
>
> With Borland (bcc32[5.5.1] -a1 -Ve -Vx )
> sizeof(variant<int,char*>) is equal to 8.
> Shouldn't this size be 5 ?
>
>
> regards,
> bohdan
>
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk