hi,
when using the register keyword, the variable is stored in the cpu.....
does anyone know how many register variables you can have in a function? assuming x86 architecture...
Thanks
null
hi,
when using the register keyword, the variable is stored in the cpu.....
does anyone know how many register variables you can have in a function? assuming x86 architecture...
Thanks
null
I think ax, bx, cx and dx are the general purpose ones (eax, ebx, ecx and edx in 32 bits) so thats 4 registers... Usually the compiler will make some variables register vars automagically when it's set to optimizing (ie VC6++), and sometimes setting register vars explicity will choke the optimizer...
Then again, it can make loops very fast when used properly.. The compiler will make as many of the register vars you specify true register vars, and when it runs out of free registers it will just ignore the other requests, I think. Sometimes the compiler might require a spare register, say, for optimizing math, etc.. so you might not always have 4 or even 3.
.sect signature
Hmm... if I might say something about register variables...
Your compiler doesn't have to actually use register variables. According to the ANSI standard, whether or not they are implemented in any fashion is up to the implementor.
Still, it's worth experimenting with, although it's becoming a rupee of the language.
> when using the register keyword, the variable is stored in the cpu
In the days before optimisers, this was used as a 'hint' (not obligation) to suggest that the compiler place the value in a register.
Optimising compilers have a much better idea of which variables are used most often (and hence might be better in registers), and will do this every time you compile the code. Without a real good knowledge of how your compiler generates code, it's at best guesswork.
> Your compiler doesn't have to actually use register variables.
Except you still can't point at a register variable (as far as I know).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
you are right , irrespective of whether the variable is actually put in a register , one cannot point to the variable
thanks for the help guys...and sorry for late reply.
null
Just a "hint":
The best variables to put in the register are variables that are used a lot (example, loop variables).
Just thought that I would share that little tid-bit of information with you.
--Garfield
1978 Silver Anniversary Corvette