Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!ico!ism780c!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: address of function Message-ID: <13751@haddock.ima.isc.com> Date: 19 Jun 89 18:53:09 GMT References: <2700@solo8.cs.vu.nl> <370@msor0.UUCP> <1817@auspex.auspex.com> <10361@socslgw.csl.sony.JUNET> <13731@haddock.ima.isc.com> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 26 >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@haddock.isc.com), The Walking Lint