Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!oddjob!uxc!uxc.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald
From: mcdonald@uxe.cso.uiuc.edu
Newsgroups: comp.lang.c
Subject: Re: BUG - unsigned long cast to double
Message-ID: <225800049@uxe.cso.uiuc.edu>
Date: 13 Aug 88 12:11:00 GMT
References: <1239500001@osiris.cso.uiuc.edu>
Lines: 16
Nf-ID: #R:osiris.cso.uiuc.edu:1239500001:uxe.cso.uiuc.edu:225800049:000:650
Nf-From: uxe.cso.uiuc.edu!mcdonald    Aug 13 07:11:00 1988



>	printf ("y: %d -> %lf   z: %u -> %lf\n", y, (double) y, z, (double) z);

>	y++; z++;
>	printf ("y: %d -> %lf   z: %u -> %lf\n", y, (double) y, z, (double) z);

I tries this on my IBM-PC with microsoft C 5.1 and of course got 
garbage. The reason is obvious: %d SHOULD be %ld and %u should be %lu.
With these changes, the output, all 4 numbers, are exactly what one
would expect for a two's complement integer machine. The problem
with the original is that printf picks up the wrong bytes to output,
due to the size of the integer arguments not agreeing with the
format specifications. Try a corrected program and see what happens.

Doug McDonald