Angel
5/12/2011 9:15:00 PM
On 2011-05-12, Free Willy <nospam@nospam.com> wrote:
>
> Say the CPU has only AL, BL, CL, DL or eight 8 bit registers, and if
> want to declare 10 register variables in my code, is it possible to do
> it?
The"register" specifier is a hint for the compiler; the compiler
is not required to follow it. If it's not possible on a given
architecture, then of course the compiler will ignore it and treat the
variable like any other.
> Say size_of(float) is the same as size_of(int), is it possible to define
> a "register float" variable? How will the register get converted between
> int and float?
Size or type don't matter, you can give any automatic variable the register
specifier. The compiler will assign an actual register if it is feasible
to do so. This varies per implementation.
Internally, any type of variable is represented as a number of bits,
which is the only thing a computer can work with. If the number of bits
required to represent the variable can fit in a register, the compiler
may do so. No special conversion is needed; a variable in a register is no
different from a variable in normal memory, except that you cannot have a
pointer to a register.
--
"C provides a programmer with more than enough rope to hang himself.
C++ provides a firing squad, blindfold and last cigarette."
- seen in comp.lang.c