Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!mips!batman!rudy From: rudy@mips.COM (Rudy Wang) Newsgroups: comp.sys.mips Subject: Re: RISC/C V2.0 bug Message-ID: <37026@mips.mips.COM> Date: 14 Mar 90 22:01:31 GMT References: <2597@cs-spool.calgary.UUCP> Sender: news@mips.COM Reply-To: rudy@mips.COM (Rudy Wang) Organization: MIPS Computer Systems, Sunnyvale, CA Lines: 52 In article <2597@cs-spool.calgary.UUCP> cliff@.UCalgary.CA () writes: >Hi Netters : > > I'd like to report a bug in the RISC/C 2.0 compiler. Given the source > code below, and the contents of the data file "5577". This program > kicks out 12 zeros. If all instances of "short int" are changed to "int", > the bug goes away. > > I suspect that in the "short int" case, that only the top 16 bits of > an "int" are actually being placed into "i"... > > Any thoughts/comments would be appreciated. I'm running on RS-2030's > using RISC/C V2.0 under RISC/os 4.10. > >------------------------------------------------------------------------------- >#include >int j; >main() >{ > int rfd; > FILE *fp; > short int i; > fp = fopen("5577","r"); > for(j=0;j<12;j++) > { > fscanf(fp,"%4d ",(short int *)&i); ^^^ > printf("%d ",(short int)i); ^^ > } > close(fp); >} >------------------------------------------------------------------------------- > and here's the input file: > > 1747 1754 1767 1775 1804 1784 1782 1775 1751 1712 > 1674 1624 1589 1550 1505 1476 1450 1415 1364 1351 .... >------------------------------------------------------------------------------- >Cliff Marcellus UUCP : {any backbone}!calgary!ssg-vax-a!cliff >Dept of Physics and Astronomy DOMAIN : cliff@ssg-vax-a.phys.UCalgary.CA >The University of Calgary SPAN : CANCAL::CLIFF >OPINIONS WITHIN ARE MY OWN AND DO NOT REFLECT THOSE OF THE UNIVERSITY OF CALGARY Try using "%4hd" and "%hd", you'll like it. To get more info on the scanf format string, do "man fscanf" and go through it carefully. -- UUCP: {ames,decwrl,prls,pyramid}!mips!rudy (or rudy@mips.com) DDD: 408-991-0247 Rudy Wang (or 408-720-1700, Ext. 247) USPS: MIPS Computer Systems, 930 Arques, Sunnyvale, CA 94086-3650 Quote: I think they're for 1 AM - Descartes, about his midnight snacks