Macros Are Evil

Precompiler text replacements, or Macros, are like Scientific Theories. They're often formed before they can be observed at all. Hence, they must be tested under every circumstance because one does not often see the code after such replacements are done. Thus one may not know how horribly mangled their code is until the compile returns such an error like "Missing ) before ;" for a line of code like "TestWidth42(42);" Imagine TestWidth42 {#define Testwidth42(a) (((a) == 42)}

Worse yet, a required macro not tested in one header is used in a later project which cannot edit said header. Often the victims never get to face the perpretrator who left the department years ago, or is tucked away in another company due to a third party purchase.

--LeeLouviere


When one appreciates that macros are better than typedefs, one may masterfully conjure such code as:

 #define declfunctptr(a) (int((a))(int)) 
 declfunctptr(*thisfuncptr); 
 thisfuncptr = (declfunctptr(__cdecl*))GetProcAddress(handle, “FunctionName”); 


This should really be named CeeStyleMacrosAreEvil?. Real macros such as those provided by CommonLisp are anything but.


EditText of this page (last edited September 28, 2010) or FindPage with title or text search