Post by BillOn Feb 8, 7:48 am, Michael Schnell
Post by Michael SchnellPost by Billint i;
i = 10/0;
It's evaluated on compile time. So it can't crash (but it should result
in a compiler error or warning).
The compiler could insert code that crashes (or produces a signal or
whatever behaviour is deemed appropriate) at run-time. But it does
not, because the behaviour when not doing an evaluation at
compile-time is not to crash or produce a signal. In contrast, on an
AMD64 box I also get a warning at compile-time, and a SIGFPE at
run-time.
Post by BillThis does give a warning at compile time because the constant zero is
there. What concerns me is when the denominator is a variable that
takes the value of zero while the application is running. There is
neither a compilation warning nor any indication that a divide by zero
is occurring when the application is running.
Yes, that's a property of the PowerPC archictecture. AFAIK the theory
of the hardware designers was that the compiler should produce code
equivalent to:
q=n/d;
if (d == 0)
raise(SIGFPE);
The idea is that the check would be performed during the latency of
the division, so it would usually not cost extra time. So one could
make the hardware simpler by not putting in the check there. I may be
confusing PowerPC with another RISC architecture (most likely MIPS)
wrt this aspect, though.
But obviously gcc does not do this (there does not even seem to be an
option to turn this on). Do other C compilers for PowerPC (from IBM,
Apple or Motorola generate such code)?
Followups set to comp.os.linux.powerpc.
- anton
--
M. Anton Ertl Some things have to be seen to be believed
***@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html