anonymous <iu*********@yahoo.co.in> wrote:
[...] Even worse, when the compiler reads that file it has no idea at all
what 'struct a' is or means. It doesn't know that 'struct a' has been
(or may only will be) declared in a different source file. [...]
But when I create the executable, both the .o files are used:
gcc -o lex.yy.o main.o
so, the definitions must be visible - right?
But then you're already linking. But what you got was an error
message from the compiler. And the compiler only deals with
single files at a time (if you don't count included files, but
they simple are more or less pasted in the source). So, when
the compiler sees your yy.c file (or however it's called) it
finds the definition of the structure and creates an .o file from
it without problems. But when it gets to main.c (the one where you
also use the structure), it has forgotten everything it did see in
the other file (typically, it's a completely new invocation of the
compiler) and so it has no idea what that structure is supposed to
be and complains, and you don't even get a main.o file. The easiest
way to make the type "struct a" visible to both files is to put the
definition into an additional include file that then gets included
from both files.
Regards, Jens
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de