From: Claudio Jeker Date: 2006-02-09T09:41:55+09:00 Subject: Re: boolean annoyance On Thu, Feb 09, 2006 at 09:15:54AM +0900, Austin Ziegler wrote: > On 08/02/06, Claudio Jeker wrote: > >> It's actually the most illogic part of languages like C that treat 0 > >> as false. Believe me, having spent most of my programming life using > >> C/C++ and being used to that, I make mistakes regularly whilst writing > >> Ruby code. > >> > >> 0 is an integer and quite often a valid value. C's treatment of 0 as > >> false is convenient in some situations but horribly inconvenient in > >> others. Because if I'm expecting an integer and zero is a legal > >> value, then you have to start playing around in your conditionals... > >> "Okay, today any -1 is false"... or even at different levels than > >> that. Part of the problem is that C doesn't have an actual NULL... > >> NULL is just defined as zero. Overlap, explosions, crash and burn... > > If you are inspecting a integer against nothing end everything is just > > legal, why are you inspecting it? > > Sorry, but that doesn't work. If you have something that returns an > integer value -- consider strtol(3). This can return *any* valid integer > value, but if you get a 0, LONG_MAX, or LONG_MIN, you have to *then* > check errno to see if the conversion was, in fact, successful. (And the > conversion could be unsuccessful for any number of reasons.) This is not correct. strtol(3) does not return 0 in case of an error. It sets errno to ERANGE and returns LONG_MAX or LONG_MIN. -- :wq Claudio