X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <403A301C.E8F5FE65@yahoo.com> From: CBFalconer Organization: Ched Research X-Mailer: Mozilla 4.75 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Fibonacci number References: <4038E8CA DOT 6491815E AT virginia DOT edu> <4039DD96 DOT 3F36F3B7 AT yahoo DOT com> <200402231458 DOT i1NEwKwm020904 AT envy DOT delorie DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 64 Date: Mon, 23 Feb 2004 17:09:42 GMT NNTP-Posting-Host: 12.76.140.201 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1077556182 12.76.140.201 (Mon, 23 Feb 2004 17:09:42 GMT) NNTP-Posting-Date: Mon, 23 Feb 2004 17:09:42 GMT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com DJ Delorie wrote: > > > BTW the following shows up a glitch in DJGPP 2.03 system. Calling > > the program with an argument of -1 returns the overflow condition, > > because strtoul returns ULONG_MAX rather than 0. Cross-posted to > > comp.os.msdos.djgpp for this. > > strtoul is *supposed* to return ULONG_MAX if it detects a range error. That isn't a range error IMO - the initial '-' is an illegal char, so it shouldn't convert anything, and should return 0. From N869: [#4] The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space character, that is of the expected form. The subject sequence contains no characters if the input string is empty or consists entirely of white space, or if the first non-white-space character is other than a sign or a permissible letter or digit. Here we may have a disagreement about whether a negative sign is a permissable character for unsigned values. In either case the 2.03 version of strtoul does NOT return ULONG_MAX for -2, it simply performs the usual conversion modulo ULONG_MAX+1. This is definitely not standards conforming IMO, and makes a mockery of overflow detection. [#5] If the subject sequence has the expected form and the value of base is zero, the sequence of characters starting with the first digit is interpreted as an integer constant according to the rules of 6.4.4.1. If the subject sequence has the expected form and the value of base is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value as given above. If the subject sequence begins with a minus sign, the value resulting from the conversion is negated (in the return type). A pointer to the final string is stored in the object pointed to by endptr, provided that endptr is not a null pointer. [#6] In other than the "C" locale, additional locale- specific subject sequence forms may be accepted. [#7] If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer. Returns [#8] The strtol, strtoll, strtoul, and strtoull functions return the converted value, if any. If no conversion could be performed, zero is returned. If the correct value is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type and sign of the value, if any), and the value of the macro ERANGE is stored in errno. -- Chuck F (cbfalconer AT yahoo DOT com) (cbfalconer AT worldnet DOT att DOT net) Available for consulting/temporary embedded and systems. USE worldnet address!