bug? in turbo c++

Dr. David Curtis dcurtis at crc.ac.uk
Fri Mar 8 19:32:30 AEST 1991


In article <1991Mar6.173733.430 at unhd.unh.edu> rg at msel.unh.edu (Roger Gonzalez) writes:
>the following program demonstrates this "bug":
>main()
>{
>    int     i;
>    long    j;
>
>    for (i = 0; i < 1000; i++, j = i*2)
>        printf("oh crud: %x %10d %x\r", i, j, i);
>}
>
>The third number printed is always zero.  It corrects itself if the
>second formatting string is %10ld.  Is this a new ansi-ism?  Will this
>behavior change to what my Unix cc fingers expect if I set it to K&R?
>Is it a bug?  I can see them arguing that it isn't a bug, but I find
>it an unpleasant nonbug at the very least.
>

Of course this isn't a bug. The only way it could possibly work as you
apparently intend if int and long were the same size. You seem to expect
printf() to know the size of the arguments which have been put on the
stack, but of course the only  way for it to do this is by providing if
with a (correct) format string.

Dave Curtis

Academic Department of Psychiatry,    Janet:       dc at UK.AC.UCL.SM.PSYCH
Middlesex Hospital,                   Elsewhere:   dc at PSYCH.SM.UCL.AC.UK
Mortimer Street, London W1N 8AA.      EARN/Bitnet: dc%PSYCH.SM.UCL at UKACRL
Tel 071-636 8333 Fax 071-323 1459     Usenet: ...!mcsun!ukc!mrccrc!D.Curtis



More information about the Comp.lang.c mailing list