Go Down

Topic: Best coding practice. (Read 5 times) previous topic - next topic


I'm not trying to be antagonistic; I just like correct things. And discussion.

I to like correct things. That is why I don't like someone putting words in my mouth which I have not stated.
saying "in arduino, bool maps to _Bool which is a native GCC type (but I'm not sure what it translates to)"
is not the same as saying "the arduino files defined them"

Anyone who likes correct things should know so.

Can you lay off the attacks please? Let's try to keep the discussion civil.

The arduino distribution includes a lot of things. Think of it as a house. One part of the house is the compiler itself. Another is avr-libc. Think of both of those as rooms with those names. The other rooms are frequently just called "arduino," just like the house as a whole. So, when one says something is part of "arduino" they generally don't mean "part of the compiler" or "part of avr-libc." So I hope you'll understand my confusion and not think I'm "Putting words in your mouth" --- that's how I understood them.

Also, I tend to think of avr-libc as part of gcc (while that is not entirely correct, they are almost always together). So, to me, "a native GCC type" could mean one that's defined in avr-libc or gcc (although I see now that "native" probably means it's part of the compiler itself). Thus, when one says that something is mapped to a native gcc type, they generally mean that it's mapped outside of gcc itself, since the internals are largely irrelevant in this context.


_Bool is a C99 type, bool is a C++ type.  Both take a single byte, same as unsigned char, signed char, and char data types.  Note, _Bool is C only and bool is C++ only, unless some other include file has done a #define to map one into another.  Since the Arduino IDE uses C++ for compiling .ino/.pde files, you should use the 'bool' type.


Speaking of splitting hair... Oddly, the arduino ide (I've tried 1.0.1) highlights boolean but not bool...


bools are bools.

They shouldn't really be interchangable with ints, it's one of the language compromises made for backwards compatibility with C.

I think you code will improve if you treat them as if they weren't interchangable. The compiler is perfectly capable of optimizing away statments like "if (x==1)", it output the same code as "if (x)".

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)


I think your code will improve if you treat them as if they weren't interchangeable.

I totally agree.

Go Up