[gameprogrammer] Re: C-Code Error interpretation

Remove 'static' from the declaration in the .c file.  That should fix
your compile problem.  'static' is basically indicating that the
variable isn't global, usuable over all source files, and so, can
only be used in the source file where it is defined.  

If the variable is only used in the one source file then remove the
line 'extern ...' from the header as it is unnecessary and keep the
'static' decalation in the .c as is.  You only put stuff in the
header for things you want to share with the other source files.

I find to keep things simple and sane, if you need to get and set a
variable in another source file, create and use get and set function
calls to do that operation instead of accessing the variable
directly.  I.E. try not to use 'extern ...' to get to varaibles in
other source files.  

--- Scott Harper <lareon@xxxxxxxxxxx> wrote:

> Okay, so I checked the usage throughout the project (I love XCode),
>  
> and the variable ONLY occurs in the header file and the one source 
> 
> file...  Would it be more proper to remove the reference to the
> file  
> in the header, then, rather than remove the static keyword? 
> (Sorry,  
> like I said, I'm generally a Java programmer, and I'm looking into 
> 
> taking some classes on C so I can understand all of these  
> complexities better.)
> 
> --Scott
> 
> On 31 Jul, 2005, at 7:43 PM, Dave Slutzkin wrote:
> 
> > On Sun, 31 Jul 2005 19:19:48 -0600, "Scott Harper"  
> > <lareon@xxxxxxxxxxx>
> > said:
> >
> >> Sorry to bother, but I'm trying to get some code compiling so I
> can
> >> start working with it, but I'm running into some errors (two
> left
> >> now, actually) that I don't understand how to resolve.
> >>
> >> First off, there's "static declaration of 'variable_name'
> follows  
> >> non-
> >> static declaration", and then it links back to both places it's
> >> declared:
> >>
> >> *.h -- extern int variable_name;
> >> *.c -- static int variable_name;
> >>
> >
> > Static says to the linker 'no need to make this accessible
> outside  
> > this
> > file'.  Extern says to the linker 'find this in another file'. 
> As I
> > understand it, the linker should complain, because (I can't  
> > remember the
> > terminology exactly) the variable hasn't been declared with
> external
> > linkage, so other compilation units shouldn't be able to access
> it.
> > Does this make sense?
> >
> > So I think the fix is to just get rid of the static from the
> > declaration.  Obviously the Microsoft linker is slightly
> non-standard
> > here.
> >
> > Hope that helps,
> >
> > Dave.
> > -- 
> >   Dave Slutzkin
> >   Melbourne, Australia
> >   daveslutzkin@xxxxxxxxxxx
> >
> >
> >
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> >
> >
> >
> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: