Masseman
Masseman

Reputation: 379

Preprocessor macros in the C++ standard

I was surprised to see that ATOMIC_FLAG_INIT is described as being a preprocessor macro that is defined in the C++11 standard. Is this something of an exception, or do the new C++ standards really cover the preprocessor step?

To me the preprocessor is a practically language of its own, and the tendency nowadays seems to be to discourage using it.

Upvotes: 1

Views: 1977

Answers (1)

You
You

Reputation: 23774

Of course the C++ standard covers the preprocessor; in fact, there's a whole chapter on it in the standard. The third and fourth phases of translation deal primarily with the preprocessor.

The C++ standard also specifies many predefined macros; assert is also a macro as are the atomic initializers as you've discovered.

There are still situations where macros are useful, but many of the most common use cases are better covered by features of recent C++ standards, such as constexpr functions/variables.

Upvotes: 8

Related Questions