home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / apollo / 3139 < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.2 KB  |  44 lines

  1. Newsgroups: comp.sys.apollo
  2. Path: sparky!uunet!munnari.oz.au!metro!usage!spectrum!cameron
  3. From: cameron@spectrum.cs.unsw.oz.au (Cameron Simpson)
  4. Subject: an annoying bug in the C compiler ...
  5. Message-ID: <1992Jul29.102800.10843@usage.csd.unsw.OZ.AU>
  6. Sender: news@usage.csd.unsw.OZ.AU
  7. Nntp-Posting-Host: fuligin.spectrum.cs.unsw.oz.au
  8. Reply-To: cameron@spectrum.cs.unsw.oz.au (Cameron Simpson)
  9. Organization: CS&E Computing Facility, Uni Of NSW, Oz
  10. Date: Wed, 29 Jul 1992 10:28:00 GMT
  11. Lines: 31
  12.  
  13. Observe the (short) C program listed below.
  14. That -2147483648 is the value of MIN_INT and MIN_LONG.
  15. When compiled and run, eg
  16.  
  17.     cc it.c
  18.     ./a.out 147
  19.  
  20. the puts() gets executed. Ugh. Bumping the constant by one makes things
  21. work. A bit suss, no? This is going to bogosify the code I'm fixing...
  22.     - Cameron Simpson
  23.       cameron@cs.unsw.oz.au
  24.  
  25. #include    <stdio.h>
  26. #include    <stdlib.h>
  27. #include    <limits.h>
  28.  
  29. int
  30. main( int argc, char    *argv[])
  31. {
  32.     int        l;
  33.     unsigned long    ul;
  34.     char        *cp;
  35.  
  36.     l=strtol(argv[1],&cp,0);
  37.     fprintf(stderr,"\"%s\"=%ld, left at \"%s\"\n",argv[1],l,cp);
  38.     if (l <= -2147483648)
  39.         puts("argh!!\n");
  40.  
  41.     ul=strtoul(argv[1],&cp,0);
  42.     fprintf(stderr,"\"%s\"=%lu, left at \"%s\"\n",argv[1],ul,cp);
  43. }
  44.