Anonymous union in VC++ 7
I'm sorry I cannot reproduce the problem with a sample
code. I've tried recreating the problem with a test
project but cannot do so. Specifically, the exception
thrown is 'Run-Time Check Failure #2 - Stack around the
variable '$S1' was corrupted.'
Here's a small snippet.
.
.
some code and local vars.
.
.
union
{
PBYTE pByte;
void* pData_t;
Quote:
};
DWORD dwRecSize = MaxRecordSize;
pByte = new BYTE[ dwRecSize ];
.
.
code and local vars
.
.
.
delete [] pByte;
.
.
code and local vars.
.
.
.
Then exception thrown at exit of function.
But if I use
union foo
{
PBYTE pByte;
void* pData_t;
Quote:
} bar;
DWORD dwRecSize = MaxRecordSize;
bar.pByte = new BYTE[ dwRecSize ];
.
.
delete [] bar.pByte;
then everything is fine.
Quote:
>-----Original Message-----
>>How come anonymous union are allocated differently on
the
>>stack then a tagged declared union ?
>>It doesn't matter where it gets allocated in the stack
>>but sometimes it gets allocated in the same spot as
other
>>auto vars and causes the runtime stack check to throw
an
>>exception.
>Do you have a small code snippet that illustrates this
problem?
>Dave
>--
>MVP VC++ FAQ: http://www.mvps.org/vcfaq
>My address is altered to discourage junk mail.
>Please post responses to the newsgroup thread,
>there's no need for follow-up email copies.
>.