tags:

views:

137

answers:

2

Hi,

I'm using EXIT_FAILURE macro, so I need to include stdlib.h or cstdlib. But I don't know what the difference is. Should I use cXXX style header file rather than XXX.h?

Thank you.

+4  A: 

As EXIT_FAILURE is a macro, it makes no difference which you include. The cstdlib version will put the names of all the functions into the std namespace, so you can say things like:

std::exit(0);

but as macros don't respect namespaces, you can't say:

std::EXIT_FAILURE
anon
Thanks, but I can still call `exit(EXIT_FAILURE)` without `std::` when I include `cstdlib`.
Brian
@Brian Yes, the exit function will be in both the global and the std namespaces,
anon
+2  A: 

<cstdlib> is just <stdlib.h> wrapped in the std namespace. You should use <cstdlib> in order to be keep your global namespace clean.

CharlesB