C linkage query

Guy Harris guy at auspex.auspex.com
Sat Jun 10 03:45:32 AEST 1989


>I'm not sure what you are asking,

I think he's asking "does anyone have a C compiler + linker incapable
of handling the given example?"  (in fact, that's what he did ask!)

A bit of (possible) background:

The C compilers that I've used - all UNIX ones - will not blithely
generate code that causes a symbol table entry to be made for symbols to
which no reference is made.  I.e., the mere *appearance* of the line

	extern int foo;

in a program will not change the generated object file.

The question was whether there *is* a compiler in which the mere
appearance of a line like:

	extern int foo;

in a file that contains no references to the "foo" declared by that line
will cause the object file generated by that compiler (we assume here
that the compiler *does* generate object files, which are to be linked
by a linker - as indicated by "C compiler + linker") to contain an
external reference to "foo" in its symbol table, such that said external
reference *must* be satisfied in order to successfully link that object
file into an executable image.

I.e., if you compile a file containing

	extern int foo;

	main() {}

and link that *with no other object files and with no libraries that
define "foo"*, will the link fail?

Several people have given examples where it *doesn't* fail, but I don't
know that those are interesting in this case; the existence of 1 million
compiler/linker pairs in which it doesn't fail doesn't demonstrate that
no compiler/linker pair exists in which it *does* fail. 



More information about the Comp.lang.c mailing list