(For future reference: It's better to put your question
in the body of your message rather than just in the Subject
line. The display of the Subject is pretty much at the
whim of the news client or mail reader, and is sometimes
at a considerable distance from the message body -- maybe
in a different window, for example, possibly obscured from
view by the message window. For those who may wonder what
John asked, it was "should `float* foo = 12345' be legal?").
John wrote On 11/17/06 11:54,:
6.3.2.3 seems to say "yes", but 6.5.16.1 seems to say "no".
6.3.2.3 says that it is possible to make the conversion,
but not that the conversion is automatic. It is also possible
to convert "pointer to struct" to "pointer to initial element,"
but even though the conversion is permitted it doesn't mean it
"just happens."
Reason I'm asking is that the Ogg Vorbis source uses this pattern, and
although it compiles fine on MSC and gcc 4, it does not compile on
Freescale's C compiler - so my question is, who's right?
A diagnostic is required, because 6.7.8/11 says that the
initialization of a scalar is subject to the same constraints
as simple assignment, and the code at hand does not meet the
constraints of 6.5.16.1/1. Having issued a diagnostic, the
compiler is then free to behave as it likes; it may even
"compile" the diagnosable code into something useful. Then
again, it may not.
(See your gcc documentation for information about how to
get it to compile Standard C instead of "gcc C," and how to
enable its copious and helpful warnings. I'm not acquainted
with the other compilers you mention; maybe they, too, can be
made to operate in less or more loosey-goosey modes.)
If you've really no alternative except to use the vile
code pretty much as it stands, you can try
float* foo = (float*)12345;
.... despite the caveats of 6.3.2.3/5.
--
Er*********@sun.com