In said:
Peter said:
Neelesh Bodas ____:
register char buff[outSTDBuffer];//// where
Defining register variable of array type produces undefined behavior
in C, because any attempt to use the array in any way, even with a
subscript, results in the address of its first element being taken.
Taking the address of a register variable in C is illegal.
"Register" is only a programmer's request - the compiler is not
required to obey. One would deduce that it hasn't, since it can't.
That sounds reasonable, but it doesn't work that way. The compiler
isn't required to obey anything anymore, as the code causes undefined
behavior.
You miss the point, I think. Perhaps it's different in C++ but
"register" is like "inline" in C, in that the compiler is not required
to obey the directive - indeed, it can't, since there are a limited
number of registers on the chip, and you can define an arbitrarily
large number of register variables.
Or are you perhaps saying that qualifying an array with "register"
is disallowed? In that case, the compiler ought to flag an error.
C90 requires automatic and register variables of aggregate type
(struct, array, or union) to have initializers containing only
constant expressions. (Many compilers do not adhere to this
restriction, however.)
(
http://david.tribble.com/text/cdiffs.htm)
I deduce that register arrays are directly allowed for in the C90
standard, if that quote is accurate. They would have to be small
arrays, or else the compiler would have to do a no-op there.
C99 removes that restriction, allowing non-constant expressions to
be used in such initializers.
C++ allows non-constant expressions to be used in initializers for
automatic and register variables. (It also allows arbitrary
non-constant expressions to be used to initialize static and
external variables.)
The logic is similar to like ' a /= 0; ' // it can't do this, so it
hasn't?
Well, it would have to be only a similarity, since a/=0 is perfectly
doable, at least for floats, and results in a well-defined undefined
result.
Peter