address of function

Karl Heuer karl at haddock.ima.isc.com
Tue Jun 20 04:53:09 AEST 1989


>I can't think of any context in which the language cares whether an rvalue is
>a "constant" or not.

I must have been asleep when I wrote that.  (Actually, I misunderstood the
terminology as being yet another manifestation of the misbelief that "an array
is just a constant pointer", and failed to note that it really was relevant to
the question.)

Of course the language does care about constant expressions; they specify the
width of a bitfield, the value of an enumeration constant, the size of an
array, the label of a |case| statement, the conditional of a preprocessor #if,
and (in the example under discussion) the initializer for an object of static
storage duration.

The question was whether a cast is permitted in a constant expression.  The
answer is "Yes, but only from arithmetic types to integral types" in the first
four cases above (integral constant expressions); "No, not at all" in the case
of a preprocessor #if.  For initializers, the language seems to accept
anything that's well-defined, including pointer-to-pointer casts.

>>	int	this[100], *that = (int *)&this;

So this is indeed legal (though, as I said before, writing it as "&this[0]"
eliminates the need for the cast, and is almost certainly clearer).

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list