Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-01-05 15:10:06

"Vesa Karvonen" <vesa_karvonen_at_[hidden]> writes:

> David Abrahams:
>>Vesa Karvonen:
>> > to the Boost Preprocessor library to help detect whether flag like macros are defined. These
>> > macros would make it easier to move some logic from unusable #if blocks into usable macros.
>>Can you show an example of such a transformation?
> I got this idea while reading the following thread on the
> comp.programming newsgroup:
> I thought about suggesting use of macros (with help from Boost.Preprocessor), which would allow using
> code like this:
> #pragma SECTION(RXFILTERS_C,rxdata,ADC_output)
> // ...
> While writing the answer, I got bored writing the "BOOL" versions of
> the macros,

What are those, for us mortals, please?

> so I started thinking about how to detect whether a
> macro was defined. The BOOST_PP_IS_EMPTY(), etc... macros that I
> came up with are not a complete replacement for defined(), but they
> can help (especially in probably the most common case when a macro
> simply serves as a flag and is defined to be either empty or 1 (this
> excludes __cplusplus and many other compiler defined flags in the
> general case, btw)).

A more useful (and I think easier) test for many purposes might be
empty or >0.

   #define CONFIG_MACRO 0

Is often a mental-model match for

   #undef CONFIG_MACRO

> I think that repeating #if blocks, often using defined(), could be
> extracted from quite a few programs written in C or C++ that have
> been ported to multiple platforms. I don't have more specific
> examples in mind, however.

I see.

                       David Abrahams
   dave_at_[hidden] *
Boost support, enhancements, training, and commercial distribution

Boost list run by bdawes at, gregod at, cpdaniel at, john at