extern declaration inconsistency
Gary Samad
gary at mit-eddie.UUCP
Wed Apr 4 12:39:03 AEST 1984
I spent hours debugging this--anyone know why it is a problem?
Is it a 'feature' or is it a 'bug'?
in file foo.c:
char ch[32];
foo()
{
strcpy(ch,"string");
printf("&ch=%x\n",ch);
}
in file ref.c:
extern char *ch;
ref()
{
printf("&ch=%x\n",ch);
printf(ch);
}
in file main.c:
main()
{
foo();
ref();
}
The program prints:
&ch=2eb4
&ch=64abc
Segmentation fault (core dumped)
(The addresses are aproximately correct)
The compiler didn't resolve the extern char correctly!
Replacing the 'extern char *ch' with 'extern char ch[]' fixes it!
Does anyone know why?
By the way, this is with the 4.1BSD compiler running under Eunice.
Gary Samad
decvax!genrad!mit-eddie!gary
More information about the Comp.lang.c
mailing list