bool and C/C++ interoperability
When I write a function in C, which may also prove useful in a C++ context, shall I use the bool macro or not? Could that lead to compati开发者_如何学运维bility issues, at C and C++ both define a bool type (well, C befines _Bool, but you know what I mean :-))?
Why not use int
? It is always properly supported.
The only reason to use bool
would be if you knew for sure that your code would be used only in modern C and C++ environments. But if there was any chance it would have to run on some old legacy compiler, perhaps for an obscure embedded processor, someone would have to insert macros and massage the code.
If you are very interested in conserving memory, you could use a char instead.
精彩评论