External structs - newbie question



I'm having difficulty with a struct in two of my c files.

The header file for csd.c (the main program) contains the typedef for a
struct called tiles. There is only one struct in use (called "map")
throughout the time that the program is run, and as it's used by
virtually all of the functions it's currently a global. I realise that
this is probably bad practice but I'm still pretty far down the curve
when it comes to c.

The file org.c contains some code which alters certain of the values
within "map". I'd like to declare "map" in csd.c and then use extern
to tell org.c that it exists. Unfortunately, nothing that I do seems
to be able to achieve this. I'm definitely including the typedef in
both files, but if I put a statement like "extern map" in org.c and try
and compile it gives an error "subscripted value is neither array nor
pointer" when it gets to the line "map[i][j].terrain = 1;".

The only way that I can get the thing to compile is to have a header
file shared by both csd.c and org.c which contains the typedef followed
by the declaration of the global variable map. This makes me nervous
because as far as I can see the global "map" is being declared twice -
once by each of the files.

Any ideas?

Simon

.



Relevant Pages

  • Re: External structs - newbie question
    ... The header file for csd.c contains the typedef for a ... by the declaration of the global variable map. ... Put an extern declaration of map in the header file, ...
    (comp.lang.c)
  • Re: External structs - newbie question
    ... The header file for csd.c contains the typedef for a ... There is only one struct in use ... Declaring it in a header file is the right way to go. ... If you put the keyword extern before the declaration, it will not be a problem declaring it twice. ...
    (comp.lang.c)
  • Re: Typedef removal tool
    ... allow spatch to not only change typdef usages with simple struct uses ... but also redefine a typedef declaration to a simple struct definition ... For upstream work I don't expect as much macro ... If a header file is included, then spatch is willing to generate patches ...
    (Linux-Kernel)
  • Re: Inplace array (mex)
    ... I'm working through a function that provides the automatically C-structure definition of the mxArray. ... % Building the typedef of internal structure MxArray by looking inside ... % the header file include file MATRIX.H. ... % Look for the line containing "struct mxArray_tag {" ...
    (comp.soft-sys.matlab)
  • Re: External structs - newbie question
    ... The header file for csd.c contains the typedef for a ... struct called tiles. ... There is only one struct in use ...
    (comp.lang.c)