<<thread split>>

#include <stdio.h>
struct a
{
        char aa;
        char ab;
        char ac;


};
struct b
{
        char b_a;
        char b_b;
        char b_c;
        char b_d;
        char b_e;
        char b_data[1];
};
int main()
{
struct b data_s;
struct a *req;
req  =(struct a* )data_s.b_data;
req->aa=3;
req->ab=3;
req->ac=25;
printf("%x\n",data_s.b_data[0]);
printf("%x\n",data_s.b_data[1]);
printf("0x%x\n",data_s.b_data[2]);
return 0;
}

Hi I am writing a Driver Code where the situation is like this as above.My doubt in this is that am I doing an array overflow here to the 'char variable b_data' ?? Can anyone please able to tell actually how the stack is getting populated in this case.Or is it a Stack Overflow ?? If I do "int ac" instead of "char ac" of "struct a" the program will crash in that case.I am thinking why is it so ??

I am a bit confused please help me out.The program is running successully in the OpenVMS Operating System.

Thanks in Advance,
Shubh,

Edited 6 Years Ago by Nick Evan: Added code-tags, split thread

Comments
Learn how to post a question and I may give it more attention.

Welcome to the forum, Shubh. :)

A few important suggestions for you:

1) For your problem, start a new thread. Using someone else's is called "thread hijacking", and will get people upset with you.

More people will see your thread when you start a new one, and respond.

2) When you post code, ALWAYS highlight it and click on the # icon in the advanced editor, or "Code" word in the quick reply window. That makes your code keep good formatting on the forum. Hopefully, you use good formatting in your code, to help spot bugs and show the relationship between lines of code that are primary, and those that are dependent (indented 2 - 5 spaces).

Edited 3 Years Ago by Nick Evan: Fixed formatting

Comments
Barely contained restraint here ;)
This article has been dead for over six months. Start a new discussion instead.