7.h:
int a
5.c:
#include"7.h"
#include <stdio.h>
int b;
void way();
void way() {
printf("%p\n",&b);
}
6.c:
#include "7.h"
#include <stdio.h>
void way();
int b;
int main(int argc, char const *argv[])
{
way();
printf("%p\n",&b);
return 0;
}
why can i use "gcc -std=c90 5.c 6.c" to compile it successfully!
the result is 0x10288b018 0x10288b018
same address!!!!!!but i don't use extern !why!
but i change "6.c" to :
6.c:
#include "7.h"
#include <stdio.h>
void way();
int b=8;
int main(int argc, char const *argv[])
{
way();
printf("%p\n",&a);
return 0;
}
5.c to :
#include"7.h"
#include <stdio.h>
int b=5;
void way();
void way() {
printf("%p\n",&a);
}
But the result is :
duplicate symbol _b in:
/var/folders/sb/dc6wxwf16kl7k1wrhrxjx5j40000gn/T/5-00d5c1.o
/var/folders/sb/dc6wxwf16kl7k1wrhrxjx5j40000gn/T/6-2b050b.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)