home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.apollo
- Path: sparky!uunet!munnari.oz.au!metro!usage!spectrum!cameron
- From: cameron@spectrum.cs.unsw.oz.au (Cameron Simpson)
- Subject: an annoying bug in the C compiler ...
- Message-ID: <1992Jul29.102800.10843@usage.csd.unsw.OZ.AU>
- Sender: news@usage.csd.unsw.OZ.AU
- Nntp-Posting-Host: fuligin.spectrum.cs.unsw.oz.au
- Reply-To: cameron@spectrum.cs.unsw.oz.au (Cameron Simpson)
- Organization: CS&E Computing Facility, Uni Of NSW, Oz
- Date: Wed, 29 Jul 1992 10:28:00 GMT
- Lines: 31
-
- Observe the (short) C program listed below.
- That -2147483648 is the value of MIN_INT and MIN_LONG.
- When compiled and run, eg
-
- cc it.c
- ./a.out 147
-
- the puts() gets executed. Ugh. Bumping the constant by one makes things
- work. A bit suss, no? This is going to bogosify the code I'm fixing...
- - Cameron Simpson
- cameron@cs.unsw.oz.au
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <limits.h>
-
- int
- main( int argc, char *argv[])
- {
- int l;
- unsigned long ul;
- char *cp;
-
- l=strtol(argv[1],&cp,0);
- fprintf(stderr,"\"%s\"=%ld, left at \"%s\"\n",argv[1],l,cp);
- if (l <= -2147483648)
- puts("argh!!\n");
-
- ul=strtoul(argv[1],&cp,0);
- fprintf(stderr,"\"%s\"=%lu, left at \"%s\"\n",argv[1],ul,cp);
- }
-