1. Proposed Wording
Under 2.3.5 C Preprocessor [delay.cpp]:
#include
, which is necessary until modules are in C++.
TODO
// compile-time constant #define BUFFER_SIZE 256 // better as: auto constexpr buffer_size = 256 ; // named constants #define RED 0xFF0000 #define GREEN 0x00FF00 #define BLUE 0x0000FF // better as: enum class Color { red = 0xFF0000 , green = 0x00FF00 , blue = 0x0000FF }; // inline function #define SUCCEEDED(res) (res == 0) // better as: inline constexpr bool succeeded ( int const res ) { return res == 0 ; } // generic function #define MIN(a,b) ((a) < (b) ? (a) : (b)) // better as: template < typename T > T const & min ( T const & a , T const & b ) { return a < b ? a : b ; } // (in actual code, use std::min() instead of reimplementing it)
All these macros have many possible pitfalls (see gcc docs), they hard to get right and they don’t obey scope and type rules. The C++ replacements are easier to get right and fit better into the general picture.
The only preprocessor usages that are necessary right at the beginning are:
-
for textual inclusion of header files (at least until modules become the main tool for consuming external code)#include -
for creating "include guards" to prevent multiple inclusion#ifndef