PDA

View Full Version : difference between register int and normal int



GanglyLamb
02-25-2003, 01:30 PM
First of all: i didnt wanted to put this on the C board because its not a real problem i just want to know what the difference is between a register int and a normal int.
According to my lib reference from BC 4.5


register int :to optimize access and reduce code.
Items declared with the register have a global lifetime.

So why dont we use register int where we can ( known that its possibly faster in processing) instead of using a normal int ?

Captain Penguin
02-25-2003, 01:34 PM
I don't know anything about them but maybe it's because they are platform specific? (which they may not be, I'm just conjecturing)

adrianxw
02-25-2003, 01:37 PM
I think you'll find the keyword is retained for backward compatibility reasons. Most modern compilers ignore it, they optimise register usage themselves.

>>> platform specific

The register storage class is part of the ANSI standard.

Prelude
02-25-2003, 01:38 PM
>So why dont we use register int where we can ( known that its possibly faster in processing) instead of using a normal int ?
Because the compiler can and probably will ignore your hint in the assumption that it is in a better position to know where to optimize. You also cannot take the address of a register variable even if it isn't actually placed in a register, this is typically considered a bad thing.

-Prelude

GanglyLamb
02-25-2003, 01:48 PM
So my conclusion is dont use a register int because most recent compilers wont notice the difference. With that i mean that they will see if it necesseray to have a register int and if not they'll translate my register int into a normal int.

If im wrong correct me.
Btw thx because i once saw some code with a register in it and wondered what the purpose was 4 it.

adrianxw
02-25-2003, 02:27 PM
Your right. The class specifier is at best, a suggestion. Consider, there is no restriction on the number of register variables you can declare in a routine, but there is a limited number of registers!

Let the compiler do it, by the time it has re-arranged your code, it is in the best position to decide where to put things.

GanglyLamb
02-25-2003, 04:01 PM
Thx got it now.