1. Revision History
r0: initial revision, pre-Cologne mailing
r1:
-
update "generic function" example based on feedback from sg20 in Cologne
-
style update
2. 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 IS_NEGATIVE(x) ((x) < 0) // better as: template < typename T > bool is_negative ( T x ) { return x < T {}; }
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