Also sprach Raju K V:
> hi all,
> 
> I have 2 structure of as follows:
> 
> struct a
> {
>       int x;
>       void *y;
> };
> 
> struct b
> {
>       char *u;
>       int v;
>       float z;
> };

So far so good.

> and in my code I write as
> 
> main()
> {
>       struct a a1;
>       struct b b1;
>       .
>       .
>       b1.u = "hello";

Boom! You've just caused a SIGSEV because you're assigning memory
that you haven't allocated properly.  b1.u could point anywhere. 
malloc and family are your friends.

>       b1.v = 10;
>       b1.z = 20.1;
>       .
>       .
>       a1.y = (struct b *)&b1;

Nope, that dog won't hunt. everything after your first invalid memory
reference creates undefined, probably fatal, behavior.

Kurt
-- 
COBOL is for morons.
                -- E.W. Dijkstra

Reply via email to