프로그램 사용/gcc
구조체 타입과 변수명은 구분된다?
구차니
2021. 11. 18. 12:46
gcc에서 해보는데 헐.. 이게 되네?
변수명과 구조체 타입명은 다른 영역으로 구분되나?
identifier로 동일하게 취급될줄 알았는데 아니라니?
$ cat t.c #include <stdio.h> struct help { int a; int b; int c;}; struct help a; int help = 1; void main() { a.a = 5; a.b = 7; a.c = 9; printf("%d %d %d %d\n",help, a.a, a.b, a.c); } |
$ gcc t.c $ ./a.out 1 5 7 9 |
다만, 함수와 변수명의 식별자 영역은 동일한지 에러가 발생한다.
$ cat t.c #include <stdio.h> void help() { printf("%s\n",__func__); } struct help { int a; int b; int c;}; struct help a; int help = 1; void main() { a.a = 5; a.b = 7; a.c = 9; printf("%d %d %d %d\n",help, a.a, a.b, a.c); help(); } |
$ gcc t.c t.c:11:5: error: ‘help’ redeclared as different kind of symbol int help = 1; ^~~~ t.c:3:6: note: previous definition of ‘help’ was here void help() ^~~~ t.c: In function ‘main’: t.c:19:2: error: called object ‘help’ is not a function or function pointer help(); ^~~~ t.c:11:5: note: declared here int help = 1; ^~~~ |