Possible C compiler bug on 8086 machines
Bryan Price
bytehead at bluemoon.uucp
Sat Feb 9 06:57:40 AEST 1991
alanf at bruce.cs.monash.OZ.AU (Alan Grant Finlay) writes:
>
> -----------------------------//---------------------------
>
> #include <stdio.h>
>
> main()
> {
> int x,y;
> x = 65536/512;
// You just assigned a long int to a short int here
> y = 512;
> printf("This works : %d, %d\n",x,y);
> printf("This doesn't work : %d, %d\n",65536/512,512);
// Buzzzzt! The first %d should be a %ld, since you are
// passing a long int (not a short int) for the 1st numeric
// parameter. 65536 is a long, and forces the compiler to
// pass it as a long, even if it fits in a short int.
> }
>
> ----------------------------//------------------------------
>
> And here is a sample output:
>
> This works : 128, 512
> This doesn't work : 128, 0
>
> Does anyone have any idea why?
> Is this a problem with my machine or the printf routine?
This is a problem with your mind.
#include <.sig>
More information about the Comp.lang.c
mailing list