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

  • From: thescriptdevil@xxxxxxxxx (Ashok Gautham)
  • Date: Sat, 17 Dec 2011 13:55:44 +0530

On Sat, Dec 17, 2011 at 01:12:10PM +0530, Raja Subramanian 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.

True. Interestingly, I have seen some code bases (Minix?) that use ! !
condition to make sure the value becomes 0 or 1.

For example,

        int a = 113;
        printf("%d\n", !!a);
        
will display 1

---
Ashok Gautham

Other related posts: