[En-Nut-Discussion] ANSI/ISO C, was: definitons for fcntl.h

Pavel Chromy chromy at asix.cz
Tue Nov 23 15:42:20 CET 2004


Harald,

>> However I don't see '!' as a boolean operator, because
>> C simply does not have boolean data type and '!' as used in the first 
>> example
>> is perfectly fine, if properly implemented by the compiler.
> 
> ...C doesn't know boolean data types, but boolean expressions.

well, that is just half true.
Unless we have we a "real" boolean data type, this is matter of formal definition.
I'd rather say that C has relational operators.

Even if we formally defined relational operators to produce a boolean result, or even implemented it so,
the result could not be assigned to a storage of the same type as it could not exist and would be automatically
type-casted to something else.
(Except of a 1-bit wide bit-field and even in such case the standard says:
"A bit-field is interpreted as a signed or unsigned integer type consisting of the specified number of bits")

In fact, the ISO standard (JTC1/SC22/WG14 N794) http://www.vmunix.com/~gabor/c/draft.html
formally defines result of relational operators to be of int type, with value of 0 or 1.
The result of '!' operator is also of int type.

But I believe that this is a bit off-topic discussion, started about code writing culture,
which I definitely agree is super important for such a project like Nut/OS, no doubt about that.

For those using also PICs:
A correction to my note about HiTech PICC - I have missjudged it a bit:
it does handle the '!' operator properly, even on bit variables,
but it cannot handle an assignment of int values other than 0 or 1 to a bit variable,
in this case a comparison with zero is needed.

Some in this mailing list might be also interrested in this document
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1021.pdf
dealing with "Extensions for the programming language C to support embedded processors"
(ISO/IEC draft Technical Report)

Pavel




More information about the En-Nut-Discussion mailing list