register variable is clobbered by passing parameter to a function

Dave Korn dk@artimi.com
Tue Mar 16 10:20:00 GMT 2004


 

> -----Original Message-----
> From: gcc-owner On Behalf Of Wolfgang Kuehn
> Sent: 15 March 2004 10:55

> When I declare an often used variable as register, the 
> variable is modified after calling a function.
> Example-code:
> 
> register  char often_used_variable asm ("r16"); char foo;
> void function1 (char p1, char p2, char p3, char p4, char p5) {   };

> I could not found anything about this behaviour in the 
> gcc-online-docs.

  It's right there in the bit about asm ("register"):

Docs
 -> Extensions to the C Language Family
   -> Variables in Specified Registers
     -> Specifying Registers for Local Variables

[
http://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Local-Reg-Vars.html#Local%20Reg%
20Vars ]

" Defining such a register variable does not reserve the register; it
remains available for other uses in places "

" This option does not guarantee that GCC will generate code that has this
variable in the register you specify at all times. You may not code an
explicit reference to this register in an asm statement and assume it will
always refer to this variable. "

> K&R says, the compiler can ignore the keyword. 

That's the register keyword itself; do not confuse it with the asm register
attribute, which is an entirely separate (gcc-specific) feature.


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc mailing list