SV: [Icc-avr] Module globals static?

Bengt Ragnemalm benra at imt.liu.se
Wed Oct 24 05:43:57 PDT 2007


Do you mean that there is a difference between declaring a global variable
with and without the static operand?

Is there in this matter any difference in a global variable defined in the
same file as main and a global variable in another file? (I call these
module global). I know that a variable that is defined global in another
file will only be seen by functions in that file.

The way you write make me think that if I write static to a file global
variable will not make it totally global but not static will.

/Bengt

> -----Ursprungligt meddelande-----
> Från: icc-avr-bounces at imagecraft.com [mailto:icc-avr-
> bounces at imagecraft.com] För David Brown
> Skickat: den 24 oktober 2007 11:45
> Till: Discussion list for ICCAVR and ICCtiny Users. You do NOT need
> tosubscribe to icc-announce if you are a member of this.
> Ämne: Re: [Icc-avr] Module globals static?
> 
> Bengt Ragnemalm wrote:
> > Is a variable that is global in a module also automatically static? I
> > think it is but if so, shouldn’t the strictly most correct way to define
> > the globals also be as static?
> >
> >
> 
> Yes, global variables are statically allocated, meaning they have a
> fixed address in memory (assigned by the linker) and exist throughout
> the lifetime of the program.
> 
> You can think of the keyword "static" as having two distinct effects on
> variables - it ensures that they have a statically allocated address,
> and it ensures that they have the minimum possible scope.  Thus all
> file-level data and functions should be declared "static" unless you are
> specifically defining global data or functions that should be available
> from other files.
> 
> mvh.,
> 
> David
> 
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr




More information about the Icc-avr mailing list