nanogui: typedef int MWBOOL;


Previous by date: 4 Jan 2002 05:58:50 -0000 MWWINDOFBINFO.x and .y, Dave Poirier
Next by date: 4 Jan 2002 05:58:50 -0000 Re: MWWINDOFBINFO.x and .y, Greg Haerr
Previous in thread: 4 Jan 2002 05:58:50 -0000 typedef int MWBOOL;, Dave Poirier
Next in thread: 4 Jan 2002 05:58:50 -0000 Re: typedef int MWBOOL;, Jordan Crouse

Subject: Re: [nanogui] typedef int MWBOOL;
From: "Greg Haerr" ####@####.####
Date: 4 Jan 2002 05:58:50 -0000
Message-Id: <005701c194e3$849c3000$3aba46a6@xmission.com>

: Unless I'm mistaken, a boolean value take either the value "true" or
: "false", some prefer to use "1" or "0", etc.  But in all cases, it has
: only 2 possible values, shouldn't a unsigned char be more than
: sufficient to store it instead a wasting 4 bytes of data for it?

The reason for this has to do with some old-time issues
with C compilers.  Take the following function:

int a = -1;

unsigned char f(void)
{
    return a;
}

vs

int f(void)
{
    return a;
}

if MWBOOL is used completely arbitrarily, such as for the use of
function return values, then it's a much better idea to declare a function
returning int than char, for sign extension and other old-fashioned C 
reasons.  It is for this reason and other similar reasons 
that most other software systems will always
typedef a boolean to be an int, rather than a char size. 
Many systems have big issues with taking the address of a char
sized parameter, placed as an int on the stack, as well.  There are
too many problems with older C compilers to use a "char" data
type for anything other than a known packed array.

Regards,

Greg


Previous by date: 4 Jan 2002 05:58:50 -0000 MWWINDOFBINFO.x and .y, Dave Poirier
Next by date: 4 Jan 2002 05:58:50 -0000 Re: MWWINDOFBINFO.x and .y, Greg Haerr
Previous in thread: 4 Jan 2002 05:58:50 -0000 typedef int MWBOOL;, Dave Poirier
Next in thread: 4 Jan 2002 05:58:50 -0000 Re: typedef int MWBOOL;, Jordan Crouse


Powered by ezmlm-browse 0.20.