Click here to Skip to main content
15,886,137 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
H.Brydon1-May-13 6:34
professionalH.Brydon1-May-13 6:34 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
Vaclav_1-May-13 9:04
Vaclav_1-May-13 9:04 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
jschell1-May-13 8:39
jschell1-May-13 8:39 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
Vaclav_1-May-13 9:03
Vaclav_1-May-13 9:03 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
jschell2-May-13 8:03
jschell2-May-13 8:03 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
Stefan_Lang1-May-13 21:54
Stefan_Lang1-May-13 21:54 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
Vaclav_4-May-13 5:34
Vaclav_4-May-13 5:34 
GeneralRe: Extending the C using preprocessor and other goodies - how do they interact? Pin
Stefan_Lang5-May-13 23:39
Stefan_Lang5-May-13 23:39 
I did say "if you can help it", and the implied advice was that you should avoid #define, if there is a better method. There are better methods for every single example you gave:

1. #define DEBUG
This is used for conditional compilation, to add more code that helps your debugging. Normally such a define should not be right in your code, as it specifies which path to use for compilation and which to ignore. Instead you sheould set that in your compiler options, or directly pass it as a command line argument to your compiler (something like "-D DEBUG")

Maybe what you meant was code enclosed in #ifdef DEBUG ... #endif - but I have no qualms with that.

2.#define MAX 256
Since Ansi C, you should use this syntax instead:
const int MAX=256;


3.#define max(a,b) (a < b ? b : a)
With C++ templates, you should better use this instead:
template <class T>
T max(const T& value1, const T& value3) {
   return (value1 < value2) ? value2 : value1; 
}


On a sidenote, since you mention MFC, the windows header files contain a min and max macro just like that listed above. And you don't even have to write some clever code to make it crash: just include valarray (a STL class header) in your windows application, instantiate a valarray variable and try to compile that!

You mention how you wrote code 30 years ago, and how MFC uses #define a lot. Please think about the implications: Yes, MFC used #define a lot 30 years ago, just like you did. But that doesn't mean that this is still recommended üpractice today!


Vaclav_Sal wrote:
I think stating   that #include just adds the file text is rather simplistic.

To the contrary, it is very concise. You are mixing up include options that you can enter in the project and compiler settings with the include statements in your code. These options will only tell the compiler which directories to search or skip when looking for an include file.
QuestionOwner Draw MenuItem Displaying large in Size in Debug but in release it is Ok Pin
002comp30-Apr-13 21:14
002comp30-Apr-13 21:14 
AnswerRe: Owner Draw MenuItem Displaying large in Size in Debug but in release it is Ok Pin
Richard MacCutchan30-Apr-13 21:34
mveRichard MacCutchan30-Apr-13 21:34 
GeneralRe: Owner Draw MenuItem Displaying large in Size in Debug but in release it is Ok Pin
002comp1-May-13 0:25
002comp1-May-13 0:25 
SuggestionRe: Owner Draw MenuItem Displaying large in Size in Debug but in release it is Ok Pin
Richard MacCutchan1-May-13 1:49
mveRichard MacCutchan1-May-13 1:49 
QuestionDetect specific finger tip in convexhull Pin
Dilan Shaminda30-Apr-13 19:34
professionalDilan Shaminda30-Apr-13 19:34 
SuggestionRe: Detect specific finger tip in convexhull Pin
Vaclav_1-May-13 5:46
Vaclav_1-May-13 5:46 
GeneralRe: Detect specific finger tip in convexhull Pin
Dilan Shaminda1-May-13 20:16
professionalDilan Shaminda1-May-13 20:16 
GeneralRe: Detect specific finger tip in convexhull Pin
Dilan Shaminda1-May-13 20:16
professionalDilan Shaminda1-May-13 20:16 
QuestionThe "hide_gui" key in the regedit , i want to know how does it works? Pin
ITboy_Lemon30-Apr-13 16:42
professionalITboy_Lemon30-Apr-13 16:42 
AnswerRe: The "hide_gui" key in the regedit , i want to know how does it works? Pin
Richard MacCutchan30-Apr-13 21:31
mveRichard MacCutchan30-Apr-13 21:31 
QuestionAccess structure variable value using string representing variable's name in C++. Pin
shanmugarajaa30-Apr-13 1:43
shanmugarajaa30-Apr-13 1:43 
AnswerRe: Access structure variable value using string representing variable's name in C++. Pin
Sivaraman Dhamodharan30-Apr-13 2:10
Sivaraman Dhamodharan30-Apr-13 2:10 
AnswerRe: Access structure variable value using string representing variable's name in C++. Pin
Chris Losinger30-Apr-13 4:07
professionalChris Losinger30-Apr-13 4:07 
AnswerRe: Access structure variable value using string representing variable's name in C++. Pin
Newbie0030-Apr-13 7:43
Newbie0030-Apr-13 7:43 
AnswerRe: Access structure variable value using string representing variable's name in C++. Pin
jschell30-Apr-13 9:47
jschell30-Apr-13 9:47 
AnswerRe: Access structure variable value using string representing variable's name in C++. Pin
Stefan_Lang1-May-13 22:09
Stefan_Lang1-May-13 22:09 
QuestionCatch OnKeyDown in CDialog Pin
_Flaviu29-Apr-13 23:52
_Flaviu29-Apr-13 23:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.