Re: A89: Other storage class modifiers


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

Re: A89: Other storage class modifiers




> "volatile" prevent a variable to be stored in a register, even while
> operations are performed on it. This is useful, for example, when a
> variable is used both by the main program and by an autoint. If an
> autoint try to modify a variable while it is stored in a register in the
> main program thread, the change will be lost as soon as the register is
> stored back. "volatile" solve this problem.

Yes :-)

> Concerning "register", I don't think it should be used nowadays, since
> modern compilers like GCC are efficients enough to make this choice as
> required.

There is still one need for "register". Inteligent compilers like GCC
really allocated as many possible vars in registers. But look the
following example:

int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;

Of course, all of them can not be in registers, because there is not
enough registers. The compiler will allocate some of them in registers
in according to his "estimation". But, if you want, for any reason, 
that p,q and r MUST be in registers, use:

int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,s,t;
register int p,q,r;

Zeljko Juric



Follow-Ups: