From 2a7773fcbb379b2d0fa6b429338a91362dea118b Mon Sep 17 00:00:00 2001 From: Ralph Tandetzky Date: Sat, 7 Mar 2015 20:32:33 +0100 Subject: [PATCH] Improved explanation for "Avoid Compiler Macros". --- 03-Style.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/03-Style.md b/03-Style.md index aea2d19..92a038e 100644 --- a/03-Style.md +++ b/03-Style.md @@ -233,16 +233,19 @@ There is almost never a reason to declare an identifier in the global namespaces Compiler definitions and macros are replaced by the pre-processor before the compiler is ever run. This can make debugging very difficult because the debugger doesn't know where the source came from. ```cpp +// Bad Idea +#define PI 3.14159; + // Good Idea namespace my_project { class Constants { public: + // if the above macro would be expanded, then the following line would be: + // static const double 3.14159 = 3.14159; + // which leads to an compile-time error. Sometimes such errors are hard to understand. static const double PI = 3.14159; } } - -// Bad Idea -#define PI 3.14159; ```