Re: Extern variables in *.c files
H . J . Lu (hjl@lucon.org)
Wed, 2 Jan 2002 23:42:26 -0800
On Wed, Jan 02, 2002 at 11:19:29PM -0800, Andrew Morton wrote:
>
> Alas, it doesn't quite work as we'd like:
>
> akpm-1:/home/akpm> cat a.c
> int a;
>
> main()
> {}
> akpm-1:/home/akpm> cat b.c
> extern char a;
>
> int b()
> {return a;}
> akpm-1:/home/akpm> gcc -fno-common -Wl,--warn-common a.c b.c
> akpm-1:/home/akpm>
>
> No warnings emitted. If b.c doesn't use `extern' it will fail
> to link because of -fno-common.
>
> What we'd *like* to happen is for the linker to determine that
> the `extern char' and the `int' declarations are a mismatch.
> Maybe the object file doesn't have the size info for `extern'
> variables. The compiler emits it though.
>
Compile doesn't emit the size info for
extern char a;
One way to fix it is to remove
extern char a;
and put
extern int a;
in a header file which is included by everyone.
H.J.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/