开发者

bool and C/C++ interoperability

开发者 https://www.devze.com 2023-01-28 19:04 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消