constant expressions

diamond@tkovoa diamond at tkou02.enet.dec.com
Tue Aug 14 14:05:53 AEST 1990


In article <5930 at darkstar.ucsc.edu> daniel at terra.ucsc.edu () writes:

>Should a translator identify 1-1 as ``a constant expression evaluating
>to zero,'' (even absent optimization)?

I have added comp.std.c to the distribution for this article, because
the C standard is almost vague on this as well.  If C++ maintains
compatibility with C here, then my best guess is:
  A translator does not have to compute the constant expression at
compile time, but it does have to remember that the expression is
constant.  When the value is cast (or automatically converted) to a
pointer, the compiled code has to remember that it was a constant,
check if the computation yields zero, and if so then convert it to
a null pointer.
  In other words, it is not necessary to do optimization, but if it
is not done, the result has to be "as if" optimization were done. :-)
-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.



More information about the Comp.std.c mailing list