S
SamL
I have two compilation units which define two variables of the same
name but of different types. The program compiled by xlc and gcc shows
different behaviors. I am wondering what the C standard says about
duplicate symbols. Thanks.
$ cat a.c
#include <stdio.h>
double a=0;
void b() {
a=1.444;
printf ("a=%lg &a=%p\n", a, &a);
}
$ cat b.c
#include <stdio.h>
int a=2;
void b();
int main() {
printf ("a=%d &a=%p\n", a, &a);
b();
return 0;
}
$ xlc a.c b.c
a.c:
b.c:
ld: 0711-224 WARNING: Duplicate symbol: a
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
$ a.out
a=0 &a=200005c8
a=1.444 &a=200005c8
$ gcc a.c b.c
ld: 0711-224 WARNING: Duplicate symbol: a
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
$ a.out
a=2 &a=20000d18
a=1.444 &a=20000d24
name but of different types. The program compiled by xlc and gcc shows
different behaviors. I am wondering what the C standard says about
duplicate symbols. Thanks.
$ cat a.c
#include <stdio.h>
double a=0;
void b() {
a=1.444;
printf ("a=%lg &a=%p\n", a, &a);
}
$ cat b.c
#include <stdio.h>
int a=2;
void b();
int main() {
printf ("a=%d &a=%p\n", a, &a);
b();
return 0;
}
$ xlc a.c b.c
a.c:
b.c:
ld: 0711-224 WARNING: Duplicate symbol: a
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
$ a.out
a=0 &a=200005c8
a=1.444 &a=200005c8
$ gcc a.c b.c
ld: 0711-224 WARNING: Duplicate symbol: a
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
$ a.out
a=2 &a=20000d18
a=1.444 &a=20000d24