cliff@.UCalgary.CA (03/14/90)
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 <stdio.h> 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 1329 1312 1286 1275 1271 1930 1965 1982 1975 1904 1851 1818 1778 1776 1750 1711 1691 1624 1583 1543 1508 1446 1417 1379 1348 1325 1318 1295 1291 1263 ------------------------------------------------------------------------------- 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
rudy@mips.COM (Rudy Wang) (03/15/90)
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 <stdio.h> >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