[Ilugc] [Technical] Does 'C' language specification has 'boolean' datatype ?

  • From: akilan27@xxxxxxxxx (Akilan R)
  • Date: Sat, 17 Dec 2011 14:25:57 +0530

On Sat, Dec 17, 2011 at 1:12 PM, Raja Subramanian <rajasuperman at 
gmail.com>wrote:

Since C defines any non-zero value as true, rather than defining true as 1
you better define true as !0. Ie, true is the opposite of false.

This is the only way to ensure that a test against 2 true values will work
in all cases.


If you meant to say
#define true !0

that is not going to work. Checking true against a variable with non-zero
value will still fail. [ if(a == true) is same as if(a == !0) which will
fail]

C99 booleans automatically converts all values to one or zero according to
standard rules before storing it in the variable. Therefore they should be
used in preference to defining our own and using integers as kludge.

-- 
?????? (Akilan R)
[ blog.akilan.in ]
*I should have no use for a paradise in which I should be deprived of the
right to prefer hell.*
  --Jean Rostand

Other related posts: