[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Register and static variables

From: Geoffrey Wossum
Subject: Re: [avr-gcc-list] Register and static variables
Date: Sat, 23 Mar 2002 13:57:21 -0600 (CST)


> What is the diff between declaring a 'normal' global variable and a
> static global variable?

A variable declared outside the scope of a function with the static
specifer is only visible in the file module that declared.  So for
instance, if you have file1.c and file2.c, both of which declare 

static int _my_int;  

Then each file sees the _my_int it declared, and no other files will be
able to use their _my_int's.  If it was declared without static, you would
get a linker error about multiply defined symbols, because there are two
_my_int's with global scope.

> Is it possible to declare a global variable, but forcing it to be in
> registers instead SRAM?

You can declare it with the register specifier, i.e. "register int rint;",
but this isn't a gurantee that it will be kept in a register the entire
time.  I'm not sure about gcc 2.5/3.0, but the semantics of the register
keyword is different in many modern compilers.  Many modern compilers just
regard register as a promise from the programmer that they won't alias a
variable by creating a pointer reference to it.

Geoffrey Wossum
Project AKO - http://ako.sf.net

avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]