F
fl
Hi,
I have small question about "extern" keyword. I browse website on line. Then, I have a new question about a post relevant to extern on a forum.
http://stackoverflow.com/questions/11756995/how-to-use-extern-in-c
The original post is pasted here:
..................
I have this code:
#include <stdio.h>
extern int x;
void a(){
int x =100;
printf("%d ",x);
x+=5;
}
void b(){
static int x = -10;
printf("%d ",x);
x+=5;
}
void c(){
printf("%d ",x);
x+=2;
}
int main(){
int x=10;
a();
b();
c();
a();
b();
c();
printf("%d ",x);
getchar();
return 0;
}
int x = 0;
I was sure that the fact that extern in declared here, I will have a compilation error - but everything passed. also , what is the meaning of extern when it's inside the C file itself? shouldn't it be in another file? Is there a way to declare this variable in order for this not to complile?
........
My question is about the last paragraph. Although I can understand its answer replies by others, I do not understand the original poster.
The snippet can build, why he said: "I was sure that the fact that extern in declared here, I will have a compilation error - but everything passed." Is there a typo, or something omitted, in this line?
The second question is about the last line: "Is there a way to declare thisvariable in order for this not to complile?" It was possible the original poster could not build the program with his compiler. Then, I still can understand his first comments (about my first question).
Could you help me on the understanding this poster?
Thanks a lot
I have small question about "extern" keyword. I browse website on line. Then, I have a new question about a post relevant to extern on a forum.
http://stackoverflow.com/questions/11756995/how-to-use-extern-in-c
The original post is pasted here:
..................
I have this code:
#include <stdio.h>
extern int x;
void a(){
int x =100;
printf("%d ",x);
x+=5;
}
void b(){
static int x = -10;
printf("%d ",x);
x+=5;
}
void c(){
printf("%d ",x);
x+=2;
}
int main(){
int x=10;
a();
b();
c();
a();
b();
c();
printf("%d ",x);
getchar();
return 0;
}
int x = 0;
I was sure that the fact that extern in declared here, I will have a compilation error - but everything passed. also , what is the meaning of extern when it's inside the C file itself? shouldn't it be in another file? Is there a way to declare this variable in order for this not to complile?
........
My question is about the last paragraph. Although I can understand its answer replies by others, I do not understand the original poster.
The snippet can build, why he said: "I was sure that the fact that extern in declared here, I will have a compilation error - but everything passed." Is there a typo, or something omitted, in this line?
The second question is about the last line: "Is there a way to declare thisvariable in order for this not to complile?" It was possible the original poster could not build the program with his compiler. Then, I still can understand his first comments (about my first question).
Could you help me on the understanding this poster?
Thanks a lot