floating point constants

Walter Murray walter at hpclwjm.HP.COM
Fri Jul 28 04:45:43 AEST 1989


>>Is this a valid C program?

>>main()
>>{
>>        printf("%f\n", 1.0/0.0);
>>        printf("%f\n", -1.0/0.0);
>>        printf("%f\n", 0.0/0.0);
>>}

>It's certainly not strictly conforming.  Division by zero is handled in
>an implementation-dependent way, including fatal compile-time error.

Another interpretation is that it's a valid program, as long as
you don't try to run it!  An expression involving division by
zero is not illegal unless that expression has to be evaluated,
in which case behavior is undefined.

Under ANSI C, I think it's clear that the following program is
valid, and prints the value 1.

main() { printf("%d\n", 2.0||1.0/0.0); }

Walter Murray
Not speaking for X3J11
----------



More information about the Comp.lang.c mailing list