K
Kenneth Brody
Ben said:Kenneth Brody said:The only thing "register" guarantees is that you can't take
the address of the object. The following definition "works" just
fine on my compiler, even with warnings turned to max:
register char foo[32766];
There are serious pitfalls in trying to use an array with
register class. See 6.3.2.1p3 (in C99). The last sentence is
the important part:
Except when it is the operand of the sizeof operator or the
unary & operator, or is a string literal used to initialize
an array, an expression that has type ``array of type'' is
converted to an expression with type ``pointer to type''
that points to the initial element of the array object and
is not an lvalue. If the array object has register storage
class, the behavior is undefined.
Well, I would never use such a thing in real life. I was just
trying to come up with a quick register example which would
obviously not fit in a register in most current systems. (Perhaps
the DS-9000 has such huge registers?)
In any case, I was momentarily suprised to see the compiler
complain about my trying to use the array it allowed me to
create, and was wondering what, if anything, could be done with
such a construct.
What about register struct? Is that UB as well? (Again, this is
just curiosity.)
Then there's the question "why not simply forbid register arrays
in the first place if their use is UB (or put the UB notice in
the register storage class description)?"
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>