about "anonymous union" problem
The previous project is converted from vc6.
I'v tried to new a new project from vc++.net,
(Win32 Project,
Application Type:console,
Addidtion Option:empy project),
and add the code to this project,
use default setting and "Debug" configuration,
the result is same.
and I'v tried more..
add this line: memset(logbuf,1,256);
Quote:
>> {
>> union {
>> char logbuf[256];
>> };
>> int val;
>> fprintf(stderr,"len2=%d\n",(char*)&val-logbuf);
memset(logbuf,1,256);
Quote:
>> val=3;
>> fprintf(stderr,"logbuf[180]=%d\n",logbuf[180]);
>> }
"Debug" -> "Start",
popup a dialog,
"Run-Time Check Failure #2-
Stack around the variable 'val' ws corrupted"
memset(logbuf,1,176);
is ok!
but when the third param of memset is greater than 176,
the dialog appears.
Thank you.
ps.
compiler option
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /E
Hsc /RTC1 /MLd /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo
/c /Wp64 /ZI /TP
linker option
/OUT:"Debug/test.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"De
bug/test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:IX86
kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Quote:
>-----Original Message-----
>I can't reproduce this. What compiler flags were you
using?
>BTW, the first printf isn't something you could rely
on. A really smart
>optimizer could easily detect that parts of the union
are unused and store
Quote:
>other variables in the same space. I'm not certain
that's happening here,
Quote:
>but it's possible (and possibly the bug.)
>Jason Shirk
>VC++ Compiler Team