GCC extern 실습

1 개요[ | ]

GCC extern 실습
testuser@zetawiki:~/example$ ll
total 16
drwxrwxr-x  2 testuser testuser 4096 Mar 24 22:22 ./
drwxr-xr-x 27 testuser testuser 4096 Mar 24 22:22 ../
-rw-rw-r--  1 testuser testuser  142 Mar 24 22:22 a.c
-rw-rw-r--  1 testuser testuser   49 Mar 24 22:19 b.c
testuser@zetawiki:~/example$ cat a.c
#include <stdio.h>
int g;
void plusOne();
int main() {
  g = 0;
  plusOne();
  printf("g=[%d]\n", g);
  plusOne();
  printf("g=[%d]\n", g);
}
testuser@zetawiki:~/example$ cat b.c
extern int g;
void plusOne() {
  g++;
}
testuser@zetawiki:~/example$ gcc a.c b.c
testuser@zetawiki:~/example$ ll
total 28
drwxrwxr-x  2 testuser testuser 4096 Mar 24 22:22 ./
drwxr-xr-x 27 testuser testuser 4096 Mar 24 22:22 ../
-rw-rw-r--  1 testuser testuser  142 Mar 24 22:22 a.c
-rwxrwxr-x  1 testuser testuser 8688 Mar 24 22:22 a.out*
-rw-rw-r--  1 testuser testuser   49 Mar 24 22:19 b.c
$ ./a.out 
g=[1]
g=[2]

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}