[Asterisk-Dev] "true" is -1 or 1 in boolean functions ?

Elazar Rosenthal elazar at panix.com
Wed Jan 18 15:46:05 MST 2006


In C any number other than 0 is true.
Also in C boolean true expressions evaluate to 1
try the following
main()
{
        printf("%d\n", !0);
}


-1 is a nice number for true because all bits are on.

Elazar


On Wednesday 18 January 2006 4:39 pm, Derek Smithies wrote:
> Hi,
>
> On Mon, 16 Jan 2006, Tilghman Lesher wrote:
> > On Monday 16 January 2006 04:59, Luigi Rizzo wrote:
> > > i notice some inconsistency in the return values for
> > > functions that have a boolean result - some pieces of code
> > > use -1, others use 1.
>
> Perhaps the real question is:
>
>   why are we returning 1 or -1?
>
> Surely, these are magic numbers, a coding style that is (generally) not
> approved.
>
> A quick web search shows many many coding guidelines that say,
>   "never use magic numbers"
>
> perhaps someone can provide some information that explains why these magic
> numbers are acceptable.
>
> Derek.



More information about the asterisk-dev mailing list