unsigned int assigned to double yields negative # ... Why?

Donn Seeley donn at utah-cs.UUCP
Fri Mar 18 18:19:57 AEST 1988


This was a bug of long standing in the PCC.  I fixed it for 4.3 BSD;
vendors who use PCC-based compilers have been fixing it too, although
this coverage has been spotty (I see that HP-UX finally fixes this in
6.0).  For maximum portability you should probably restrict your use of
this conversion, because the workarounds for the bug are ugly and there
are still many buggy compilers.

It's true that neither K&R nor ANSI give special mention to unsigned-
to-floating conversions, but if the compilers weren't broken, I doubt
the issue would have arisen.

Donn Seeley    University of Utah CS Dept    donn at cs.utah.edu
40 46' 6"N 111 50' 34"W    (801) 581-5668    utah-cs!donn

PS -- Yes, I fixed the obvious printf() problems before trying the
example; it'd sure be nice if people could test examples before posting
them (especially in bug reports).



More information about the Comp.lang.c mailing list