<br><br><div class="gmail_quote">On Mon, Sep 26, 2011 at 4:36 PM, Francois Pichet <span dir="ltr"><<a href="mailto:pichet2000@gmail.com">pichet2000@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Mon, Sep 26, 2011 at 6:52 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br>
</div><div class="im">> On Mon, Sep 26, 2011 at 6:09 AM, r4start <<a href="mailto:r4start@gmail.com">r4start@gmail.com</a>> wrote:<br>
>> I really don't understand why align=4 isn't correct.<br>
>> I always thought that #pragma pack only affects members of the structure.<br>
>> And __declspec(align(n)) specifies the alignment for objects of type.<br>
>> In MSVS align for B is 4 and for A is 1.<br>
><br>
> The only answer I can come up with is the model MSVC uses is simply insane.<br>
><br>
> One more attempt to get some sanity: does the following compile with<br>
> MSVC? If so, what is the output?<br>
><br>
> #include <cstdio><br>
> class A {<br>
> char c;<br>
> };<br>
> class B : public virtual A {<br>
> public:<br>
> void *p;<br>
> };<br>
> B* x = new B[10];<br>
> int main() { std::printf("%d\n", (int)(x[1].p)); }<br>
><br>
<br>
</div>it compiles and the output is 0.<br>
not sure what you are trying to test here.</blockquote><div><br></div><div>I'll guess that Eli meant to print &x[1].p (to see whether the void* pointer was aligned or not), perhaps. I modified the program to print:</div>
<div><br></div><div> std::printf("%d\n", (int)(&x[0].p));</div><div> std::printf("%d\n", (int)(&x[1].p));</div><div><br></div><div>& the result I got (in debug) was:</div><div><br></div>
<div><div>1077836</div><div>1077845</div></div></div>