is (int (*)())NULL legal when NULL is (void *)0?

Christopher R Volpe volpe at camelback.crd.ge.com
Fri Nov 16 07:50:47 AEST 1990


In article <14463 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
|>In article <13799 at crdgw1.crd.ge.com> volpe at camelback.crd.ge.com
(Christopher R Volpe) writes:
|>-In article <14457 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
|>-|>In article <1391 at gtx.com> randy at gtx.UUCP (Randy D. Miller) writes:

[Deleted example]

|>-|>No, the second is not required to be supported by the implementation,
|>-|>but the first is (3.2.2.3).
|>-What's wrong with the second example? A null pointer constant 
|>-represented by "(void *)0" is first cast to a function pointer (perfectly
|>-legal), and the resulting expression is assigned to the variable
|>-f2, of identical type, which should also be legal. Can you explain the
|>-problem?
|>
|>The problem is that you can't point to any requirement in the standard
|>that the implementation support casting (void*)0 to a pointer to function.

It seems to me that the "spirit" of the cast operator is to make
explicit a conversion where otherwise there would be no conversion
or the conversion would be implicit rather than explicit. If the
implicit conversion in example 1 is allowed, shouldn't the explicit
conversion to the same thing be allowed? 

If the above is not true, then where in the standard does it say that
an implementation must support casting an int into a float? I
don't see it in 3.3.4? Doesn't this fall into the same category?
Neither violates the constraint in 3.3.4, but then neither is explicitly
supported. Both *conversions* are supported, if done via assignment
operators.
                       
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list