{register int i, *p; p = &i;}
Wayne Throop
throopw at dg_rtp.UUCP
Fri Jul 4 06:53:27 AEST 1986
> markb at sdcrdcf.UUCP (Mark Biggar)
> IT still doesn't work for REGISTER variables!
True, true. Both K&R and the draft standard explicitly deem this
illegal. But it is worth noting what Harbison and Steele have to say
about it:
7.4.6 Address Operator
[blah, blah, blah, blah, and then the interesting part]
The original description of C specified that it was illegal to apply
the unary address operator '&' to a register variable, and some
compilers still enforce this restriction. However, since register
is treated only as a hint to the compiler and not a mandatory
requirement, it seems appropriate to allow such usage, inasmuch as
on some computers the registers really are addressable as if they
were memory locations. On the other hand, when the target computer
does not have addressable registers, applying '&' to a register
variable may simply defeat the declaration of the variable as
register, forcing it to be of class auto instead. We recommend that
new compilers take this latter approach and perhaps also issue a
warning message. In any case, such usage should be regarded as
nonportable.
This makes three points:
- 'register' is "only" a hint to the compiler, and the declaration of
a variable as register does not ensure that the variable *will* be
in a register
- therefore, '&' of register variables "ought" to be allowed, and
simply be one of those cases where the compiler might be compelled
to ignore the register hint
- (despite this "ought", it is certainly non-portable, given current
compilers and draft standards)
And to conclude, remember that the original posting in this series was a
request to make a macro "swap" such that
swap( *a++, *b++ );
would work, and the posted examples would work even if a and b were
declared register.
--
"Eschew obfuscation."
"Giesundheit!"
--
Wayne Throop <the-known-world>!mcnc!rti-sel!dg_rtp!throopw
More information about the Comp.lang.c
mailing list