"harry" <ar********@gmail.com> wrote in message
news:11********************@z14g2000cwz.googlegrou ps.com...
Hi all
I am putting a code snippet
#include "stdio.h"
#include "conio.h"
struct base{
int i;
char c;
};
struct der{
base b;
};
void FillUp(der *ptr)
{
ptr->b.i=10;
ptr->b.c=65;
}
int _tmain(int argc, _TCHAR* argv[])
{
der d;
FillUp(&d);
getch();
return 0;
}
I have a similar model in a bigger project. I am seeing some kind of
stack corruption. The value of "c" is not getting written to the
address at d.b.c when the function is called. Can anyone give me some
inputs abt when such a thing is possible?...or maybe point me to a link
where i can read about some stack issues.
thank you in advance...
Harry
I don't see any problem here. More likely, what you're seeing isn't related
to this code, but is caused by some other code problem and only exhibited in
this fashion. Look for any uninitialized pointers, or writing beyond the
end of arrays (such as indexing them from 1 instead of from 0, or forgetting
that a C-style string needs a null terminator at the end).
Try debugging. Check the address of d, and compare it to the value of ptr.
They should be the same. And step through, watching for any use of a
pointer that's not initialized yet, or has already been deleted.
But there's no problem in the code above, at least as far as setting the
members of d is concerned.
(By the way, I think explicitly researching "stack corruption" is likely a
waste of time.)
-Howard