🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2177

Re: strtoul on negative numbers

#2177
From: T. William Wells
Date: Thu, 01 Oct 1992 07:59
18 lines
1071 bytes
In article <1992Sep30.234808.19678@ptcburp.ptcbu.oz.au> michi@ptcburp.ptcbu.oz.au (Michael Henning) writes:
: All implementations I have seen return ULONG_MAX - 1.

This is the correct behavior.

: I believe that this is incorrect behaviour.
: -2 is not a value representable in an unsigned long, in my opionion.

So? Who says that the value -2 is represented?

What *is* represented is the value of 2, negated. For C,
operations like add and subtract (and negate, considered as 0-x)
on unsigned types are defined as modular arithmetic where the
result is always kept in the range 0..max-1.

---
Bill                            { rutgers | decwrl | telesci }!twwells!bill
bill@twwells.com
Technical Details
Message-ID: <BvFnJF.JMC@twwells.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!twwells!bill
References: <1992Sep30.175835.7972@lucid.com> <1992Sep30.234808.19678@ptcburp.ptcbu.oz.au>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!twwells!bill
From: bill@twwells.com (T. William Wells)
Subject: Re: strtoul on negative numbers
Date: Thu, 1 Oct 1992 07:59:37 GMT
Message-ID: <BvFnJF.JMC@twwells.com>
References: <1992Sep30.175835.7972@lucid.com> <1992Sep30.234808.19678@ptcburp.ptcbu.oz.au>
Organization: None, Mt. Laurel, NJ
Lines: 18