helpermethod
helpermethod

Reputation: 62185

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 compatibility issues, at C and C++ both define a bool type (well, C befines _Bool, but you know what I mean :-))?

Upvotes: 1

Views: 343

Answers (2)

returneax
returneax

Reputation: 709

If you are very interested in conserving memory, you could use a char instead.

Upvotes: 0

wallyk
wallyk

Reputation: 57774

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.

Upvotes: 4

Related Questions