Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!mrccrc!dcurtis From: dcurtis@crc.ac.uk (Dr. David Curtis) Newsgroups: comp.lang.c Subject: Re: bug? in turbo c++ Message-ID: <511@tin.crc.ac.uk> Date: 8 Mar 91 09:32:30 GMT References: <1991Mar6.171424.17409@nntp-server.caltech.edu> <1991Mar6.173733.430@unhd.unh.edu> Reply-To: dcurtis@crc.ac.uk (Dr. David Curtis) Organization: MRC Human Genome Resource Centre Lines: 30 In article <1991Mar6.173733.430@unhd.unh.edu> rg@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@UK.AC.UCL.SM.PSYCH Middlesex Hospital, Elsewhere: dc@PSYCH.SM.UCL.AC.UK Mortimer Street, London W1N 8AA. EARN/Bitnet: dc%PSYCH.SM.UCL@UKACRL Tel 071-636 8333 Fax 071-323 1459 Usenet: ...!mcsun!ukc!mrccrc!D.Curtis