Martin Ambuhl said:
If placebo.h is written well, it will have guards against multiple
inclusion. The header will be wrapped in something like
#if !defined(PLACEBO_H_GUARD)
#define PLACEBO_H_GUARD
/* the header contents go here */
#endif
Look in the header and find the name of the guarding macro. Use it in
your own code:
#if defined(PLACEBO_H_GUARD)
/* code to be used when placebo.h is included */
#else
/* code to be used otherwise */
#endif
Yes, that can work, but personally I'd hesitate to use a guarding
macro outside the header that defines it. If I were maintaining the
header itself, I'd feel free to change the name of the guarding macro;
it probably wouldn't occur to me that someone else might be using it.
I don't think of the name of the macro as part of the interface.
It's usually better to use something that *is* part of the interface.
For example, <stdbool.h> provides "__bool_true_false_are_defined".
If the header doesn't provide a testable macro, perhaps you can
prevail on the author to add one (which should be easy if you're the
author). If that's not feasible, you can replace each occurrence of
#include "placebo.h"
with
#include "placebo.h"
#define PLACEBO_INCLUDED
The OP's original question seemed to imply that he wants to do the
test at run time. Since the question of whether the header is
included is determined during compilation, it makes more sense to use
a preprocessor test (#if or #ifdef rather than if(...)).