V
vichy.kuo
Dear all:
Below is my program:
#include<stdio.h>
typedef struct{
int b_value;
}B;
typedef struct{
B* next;
int a_value;
}A;
int main(void)
{
A a;
//B* pb;
a.a_value=12;
//pb=a.next;
//pb->b_value=23;
a.next->b_value=23;
printf("b_value=%dvn",a.next->b_value);
//printf("b_value=%dvn",pb->b_value);
return 0;
}
The program will get segment fault or compiler will say "request for
member 'b_value' in something not a structure or union".
The program will be fine if I unmark "//" part, which is the way that
people usually to access link list.
"next" is an element of A, so a.next should be fine.
"a.next" is a pointer which point to B, so a.next->b_value seems ok.
Do my assumption correct?
Sincerely Yours,
vichy
Below is my program:
#include<stdio.h>
typedef struct{
int b_value;
}B;
typedef struct{
B* next;
int a_value;
}A;
int main(void)
{
A a;
//B* pb;
a.a_value=12;
//pb=a.next;
//pb->b_value=23;
a.next->b_value=23;
printf("b_value=%dvn",a.next->b_value);
//printf("b_value=%dvn",pb->b_value);
return 0;
}
The program will get segment fault or compiler will say "request for
member 'b_value' in something not a structure or union".
The program will be fine if I unmark "//" part, which is the way that
people usually to access link list.
"next" is an element of A, so a.next should be fine.
"a.next" is a pointer which point to B, so a.next->b_value seems ok.
Do my assumption correct?
Sincerely Yours,
vichy