[En-Nut-Discussion] is there a better set of definitons for fcntl.h ???

Pavel Chromy chromy at asix.cz
Tue Nov 23 10:50:24 CET 2004


Harald Kipp wrote:

> Typically the value of 4 is assigned to _O_NONBLOCK,
> but this is not used in Nut/OS yet.

That's a good point.

>   #define FRWMASK (_O_RDONLY | _O_WRONLY | _O_RDWR)
>   if((mode & FRWMASK) == _O_RDONLY)...
> 
> which would make the code fully independent from defined
> values?

Good idea, I personally like this one. Except of FRWMASK,
should not it rather be an underscored macro, like _O_RWMASK ?

> Btw. Rich Salz, the author of INN, sometime somewhere stated,
> that he very much dislikes using
> 
>   if(!(num-expr))
> 
> instead of
> 
>   if((num-expr) != 0)
> 
> He argued, that ! is a boolean operator and should be used
> on boolean expressions only. I learned a lot from Rich'
> source codes and respect him very much.

Well, I agree with Rich that the latter one is more clean.

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.

Despite I sometimes use '!' like that to make the code more compact, I must admit
that e.g. HiTech PICC compiler does not implement it correctly for
bit data types. (Which is really weird, as bit data type is of boolean nature.)
Test for non-equalty with zero works under all circumstances,
providing a better portability and making it the right choice.

Pavel



More information about the En-Nut-Discussion mailing list