[En-Nut-Discussion] Nut/OS finally moving to C99 types

Harald Kipp harald.kipp at egnite.de
Fri Apr 18 13:57:21 CEST 2008


Sorry in advance for becoming a bit off-topic.

Thiago A. Corrêa wrote:

> It makes a lot more sense when the return value is only for indicating
> success or failure, or enable/disable, etc.... If only two values are
> valid, there is no reason to use a broader type.

I have 3 questions:

Will the compiler accept "bool v = 2;", "int x = false" or "if (v == -1)"?

What is the size of a bool and the size of an element in an array of 
booleans?

Is stdbool.h available in any of the compiler runtimes we are using 
right now (gccavr, arm-elf-gcc, iccavr)?


> It provides the compiler with optimization opportunities, 

I'm not sure about this, but your answers to the questions above may 
convince me - in either way.


> and I'm sure
> the standards committee have seen other advantages other than just
> syntax sugar, although that is reason enough in terms of readability.

In that specific sense, can you specify "readability"? In my view, 
readability implies consistency. If some functions return 0 and -1 while 
others use true and false for the same purpose, readability suffers.

Let's assume a new function

bool foocmp(itm1, itm2);

How to explain a newbie the following difference

if (strcmp(str1, str2))...
but
if (foocmp(str1, str2) == false)...

(or too completely confuse him "if (strcmp(str1, str2) != false)" :-))


> States without any doubt that the variable can only assume 2 states,
> no more, no less. No grep'ing for that variable to see the possible
> states.

If you are more familiar with other languages like C++ or PHP, this is 
indeed confusing. If C is your daily dope, then there's usually no 
doubt, that a result value of 0 means "Everything is fine" and that it 
never means "false".

Harald




More information about the En-Nut-Discussion mailing list