Improved explanation for "Avoid Compiler Macros".

This commit is contained in:
Ralph Tandetzky
2015-03-07 20:32:33 +01:00
parent 285da913f6
commit 2a7773fcbb

View File

@@ -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. 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 ```cpp
// Bad Idea
#define PI 3.14159;
// Good Idea // Good Idea
namespace my_project { namespace my_project {
class Constants { class Constants {
public: 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; static const double PI = 3.14159;
} }
} }
// Bad Idea
#define PI 3.14159;
``` ```