[cfe-dev] Implementation of the CGRecordLayoutBuilder for Microsoft ABI.

Aaron Ballman aaron at aaronballman.com
Mon Sep 26 16:35:21 PDT 2011


On Mon, Sep 26, 2011 at 5:52 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Mon, Sep 26, 2011 at 6:09 AM, r4start <r4start at gmail.com> wrote:
>> I really don't understand why align=4 isn't correct.
>> I always thought that #pragma pack only affects members of the structure.
>> And __declspec(align(n)) specifies the alignment for objects of type.
>> In MSVS align for B is 4 and for A is 1.
>
> The only answer I can come up with is the model MSVC uses is simply insane.
>
> One more attempt to get some sanity: does the following compile with
> MSVC?  If so, what is the output?
>
> #include <cstdio>
> class A {
>  char c;
> };
> class B : public virtual A {
>  public:
>  void *p;
> };
> B* x = new B[10];
> int main() { std::printf("%d\n", (int)(x[1].p)); }

VS 2010, Win7, 32-bit build:
Debug mode prints: -842150451
Release mode prints: 230338032

Seriously.

~Aaron




More information about the cfe-dev mailing list