I have a strange problem. Here are two source code.
/*---main.c---*/
#include <stdio.h>
int d=100;
int x=200;
void p1(void);
int main() {
p1();
printf("d=%d,x=%d\n",d,x);
return 0;
}
/*---p1.c---*/
double d;
void p1() {
d=1.0;
}
I compile the code and link. I get a warnning:
/usr/bin/ld: Warning: alignment 4 of symbol `d' in /tmp/ccuZEbnu.o is smaller than 8 in /tmp/ccrTyML7.o
I excute the program and get the result d=0,x=1072693248, why not d=100,x=200 ?
This is so strange that I cannot understand. I try to print the address of d and x, I found that the address of variable d in the two source codes are totally same. I think two variable d in different source code should be different because it has no extern.
I'm a newbie. Sorry for my poor English. Thanks for your help in advance.
statickeyword is used for.externin default.