Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!ginosko!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.co.jp (Norman Diamond) Newsgroups: comp.std.c Subject: Questions about ANSI constant expressions Message-ID: <10880@riks.csl.sony.co.jp> Date: 26 Sep 89 12:13:37 GMT Reply-To: diamond@ws.sony.junet (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 45 According to the standard, a compiler may optionally fold the following constants: [a] a = 5.0 + 6.0; [b] b = 5 + 6; [c] c = 5000000000 + 6000000000; /* five billion + six billion */ If the compiler chooses to fold [a], it is required to provide at least the same range and precision at compile time as the target machine will provide at execution time. If the compiler chooses to fold [b] or [c], the standard does not seem to place any restriction on compile time accuracy. Intuitively, [b] might be expected to fold properly, because the host machine might be required to handle longs of up to around two billion (there might be a self-compiler on the host machine). But does the standard actually require this? Case [c] becomes interesting if the host machine has 32-bit longs but the target machine has 64-bit longs. A sensible implementor might decline to fold the constant. I believe the standard permits a lack of folding, and it permits correct folding. But does it actually require one of these? As far as I can tell, it permits incorrect folding as well. The situation becomes more important in the case of a preprocessor "#if" directive. Cases [b] and [c] are required to be computed at compile-time, and accuracy must be guaranteed up to a range of about two billion. So case [b] must be folded properly in the case of an "#if". What about case [c]? Is the preprocessor required to simulate the target machine's range, or is it allowed to produce incorrect results when they exceed approx. two billion? (Thanks to a friend, who probably prefers to remain anonymous for kindly providing an illegal copy of the draft standard.) -- -- Norman Diamond, Sony Corporation (diamond@ws.sony.junet) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.