At 9:03 pm -0600 2010/12/02, Brian Lanning wrote:
[...] The error over on HPUX was "floating point
exception".
My guess is that most C programmers wouldn't know that the divide
operator in C takes floats as parameters. The compiler does an
implicit conversion from into to float on x and y, does the divide on
the floats (hence floating point exception), then converts the value
back to an int for storage in z.
No. The reason you got a "floating point exception" is that Unix
traditionally lumps integer arithmetic fault together with floating point
faults under one signal, SIGFPE.
$ cat t.c
int a, b;
int main() { return a / b; }
$ cc t.c; ./a.out
Floating exception(coredump)
$ otool -tv -p _main ./a.out
./a.out:
(__TEXT,__text) section
_main:
0000000100000f20 pushq %rbp
0000000100000f21 movq %rsp,%rbp
0000000100000f24 leaq 0x00000139(%rip),%rcx
0000000100000f2b leaq 0x0000012e(%rip),%rax
0000000100000f32 movl (%rax),%edx
0000000100000f34 movl %edx,%eax
0000000100000f36 sarl $0x1f,%edx
0000000100000f39 idivl (%rcx)
0000000100000f3b leave
0000000100000f3c ret
At 10:28 pm -0500 2010/12/02, blstuart at
bellsouth.net wrote:
That's interesting as a puzzle, but I've seen
the converse:
"0123456789abcdef"[i]
in the wild. I'm pretty sure it was in some of Ken's code.
Also,
"TF"[!b]
At 8:35 pm -0800 2010/12/02, Chuck Guzis wrote:
Does any C detect integer overflow (i.e. subtracting a
large positive
number from a negative and getting a positive number back)?
The current standard allows operations on that standard signed (but not
unsigned) integer types to fail on overflow, but I'm not aware of any
implementation that does that. There is no standard way to detect overflow.
--
Kevin Schoedel <schoedel at kw.igs.net> VA3TCS