[OCLUG-devel] C and external variables

James Colannino james at colannino.org
Wed Aug 24 22:29:54 PDT 2005


Christopher Smith wrote:

>James Colannino wrote:
>  
>
>>I have a quick question about C and external variables; let's say that
>>in one file I have the following:
>>
>>typedef struct thing_ {
>>   variables;
>>} thing;
>>
>>Now let's say that I want to declare a variable in another file with
>>that external type.  How would I declare it?  Would I have to do another
>>typedef in the other file, such as:
>>
>>typedef extern thing thing;
>>
>>I'm just guessing here, so I know I'm most likely wrong.  Thanks in
>>advance.
>>    
>>
>
>extern is a modifier on the variable, not the type. Normally what you do
>is the type definition is a header that is included by the "other file".
>  
>

Now I understand.

>So, if I have type defined in "type_defined.h" that I want to have
>shared between multiple object files, then any file that uses that type
>should '#include "type_defined.h"'. No extern necessary.
>  
>

That's what I'll be doing then.  Thanks for the help.

James



More information about the OCLUG-devel mailing list