Re: bool variable.(a non-standard question)



shaanxxx wrote:

I have code which says

#define MYBOOL int

This code is very old. people who have written is not avaible. I
was thinking what could be reason.
1) bool datatype was not available that time (10 years back:
correct me if i am wrong)
2) int was word aligned (16bit and 32bit). Writter of above code
doesnt want to give choice to compiler.
if we say bool , compiler can represent this on his way (again,
correct me if i am wrong)

C still has no bool type, unless you #include <stdbool.h> in C99
systems. After which true and false will be macros that expand to
integers 1 and 0 respectively, and bool will expand to _Bool (which
is system defined, usually as an int).

However, since the dawn of time, C has defined logical expressions
(e.g. (x < y)) as returning either 0 or 1. This is why !!x can be
used to force the value to those, and why we can do arithmetical
tricks with booleans.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

.



Relevant Pages

  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: bool or BOOL in MFC projects
    ... Also, in the PDP-11 compiler, which was a real piece of trash, if you wrote ... learned it on the PDP-11 and never unlearned all the bad habits they developed. ... so every function implicity returned int. ... bool or BOOL in MFC projects ...
    (microsoft.public.vc.mfc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... even the concept of using the result of a boolean ... I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • socket programming linux
    ... bool Socket::bind (const int port) ... opts = fcntl (m_sock, ... error encountered while using g++ compiler: ...
    (comp.os.linux.development.apps)