tags 568398 + moreinfo thanks On Thu, Feb 04, 2010 at 10:10:00AM -0500, Camm Maguire wrote: > dd.c: > #include <stdio.h> > #include <complex.h> > > int main(int argc,char * argv[]) { > double complex d=0; > long l; > > sscanf(argv[1],"%ld",&l); > d=l; > printf("%d %d %d %d %f\n",(char)d,(short)d,(int)d,(long)d,(double)d); > > return 0; > } > > > c...@localhost:$ cc -g /tmp/dd.c -o /tmp/dd > c...@localhost:$ /tmp/dd 1 > 1 1 1 1 1.000000 > c...@localhost:$ /tmp/dd 255 > -1 255 255 255 255.000000 > c...@localhost:$ /tmp/dd 256 > 0 256 256 256 256.000000 > c...@localhost:$ /tmp/dd 257 > 1 257 257 257 257.000000 > c...@localhost:$ /tmp/dd 65535 > 0 -32768 65535 65535 65535.000000 > c...@localhost:$ /tmp/dd 32768 > 0 -32768 32768 32768 32768.000000 > c...@localhost:$ /tmp/dd 32767 > -1 32767 32767 32767 32767.000000 > c...@localhost:$ /tmp/dd 32766 > -2 32766 32766 32766 32766.000000 > c...@localhost:$ /tmp/dd 2147483647 > 0 -32768 2147483647 2147483647 2147483647.000000
The conversion from double to char is only defined if the value of the double, after discarding the fractional part, fits within the value range of char. In your examples, this is only the case for the first example, where the result seems correct. So please explain what the output you expected is. Falk -- To UNSUBSCRIBE, email to debian-gcc-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/20100309125016.ga14...@minet.uni-jena.de