구조체 선언에 대한것인데요.

puresupe의 이미지

1 #include
2
3 struct list_node{
4 char str[4];
5 struct list_node *link;
6 };
7
8 struct list_node *ptr=NULL;
9
10 int main(void)
11 {
12 ptr = (list_node*)malloc(sizeof(list_node));
13 printf("%d",sizeof(*ptr));
14 return 0;
15 }
16
~

null_pointer.c: In function 'main':
null_pointer.c:12: error: 'list_node' undeclared (first use in this function)
null_pointer.c:12: error: (Each undeclared identifier is reported only once
null_pointer.c:12: error: for each function it appears in.)
null_pointer.c:12: error: expected expression before ')' token

이런 에러가뜨는데

잘못된거 없지않나요?

bushi의 이미지

typedef 를 안 쓸 요량이라면

ptr = malloc(sizeof(struct list_node));

혹은
ptr = malloc(sizeof(*ptr));

OTL