TITLE: advice on when to use macros PROBLEM: swampwiz@ix.netcom.com(Jean P. Laborde ) Someone responded to this group and advocated using a define macro. I thought that was extremely bad practice in C++. RESPONSE: Using #define macros is not a bad idea, but it depends on the problem and restrictions of the project you are working on. Sometime, for speed you want just a macro and not have to make a function call. RESPONSE: kcline@sun152.spd.dsccc.com (Kevin Cline), 22 Feb 96 Using macros to define functions is a very bad idea. Use inline functions instead. This allows the compiler to decide whether inlining the code is faster than a function call. The compiler knows more about this than the programmer. Also, inline functions calls are typesafe. Macros should only be used for text-processing tricks that improve code maintainability, e.g. #define FRUIT_LIST \ FRUIT(apple), \ FRUIT(orange), \ FRUIT(pear) #define FRUIT(t) t typedef enum { FRUIT_LIST } Fruit; [ corrected. -adc] #undef FRUIT // #t produces a quoted string #define FRUIT(t) #t static const char* const FruitNameTable[] = { FRUIT_LIST }; [ corrected ] #undef FRUIT When the list gets long, techniques like this can be useful for reducing redundancies in source code. I find that as soon as I have to specify the same thing twice, and the compiler is unable to make sure they match, they won't. [ Amen. -adc ]