Click here to Skip to main content
15,896,118 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: #define Pin
Joaquín M López Muñoz6-Feb-03 9:28
Joaquín M López Muñoz6-Feb-03 9:28 
GeneralRe: #define Pin
Christian Graus6-Feb-03 9:39
protectorChristian Graus6-Feb-03 9:39 
GeneralRe: #define Pin
Joaquín M López Muñoz6-Feb-03 10:03
Joaquín M López Muñoz6-Feb-03 10:03 
GeneralRe: #define Pin
Christian Graus6-Feb-03 10:28
protectorChristian Graus6-Feb-03 10:28 
GeneralRe: #define Pin
Joaquín M López Muñoz6-Feb-03 10:31
Joaquín M López Muñoz6-Feb-03 10:31 
GeneralRe: #define Pin
Paul M Watt6-Feb-03 19:44
mentorPaul M Watt6-Feb-03 19:44 
GeneralRe: #define Pin
RChin6-Feb-03 2:01
RChin6-Feb-03 2:01 
GeneralRe: #define Pin
Gary Wheeler6-Feb-03 2:04
Gary Wheeler6-Feb-03 2:04 
The preprocessor (which handles #define's) simply performs string substitution. It does not do any expression evaluation. The end result is that int i=4*3+2+3 is what is passed to the compiler. The compiler will evaluate the statement as i=17.

This is why it is so important to parenthesize macro arguments, along with the macro itself. Since the #define is just a string substitution, it can have problems based on operator precedence. For example, suppose you have:
#define macro(a,b) a / b
If you use this macro like this:
int x = macro(4,2);
the compiler actually parses and generates code for:
int x = 4 / 2;
But, if you use it like this:
int y = macro(4,1 + 1);
the compiler actually parses it as:
int y = 4 / 1 + 1;
which has a different result from what you expect. Similarly, if you use the macro like this:
int z = macro(4,2) * 3;
the compiler parse it as
int z = 4 / 2 * 3;
Given operator precedence, the compiler will generate code for
int z = 6;
Using the macro as follows:
int z = macro(4,1 + 1) * 3;
causes the compiler to parse:
int z = 4 / 1 + 1 * 3;
which generates code for
int z = 7;



Software Zen: delete this;
GeneralRe: #define Pin
Chris Richardson6-Feb-03 18:58
Chris Richardson6-Feb-03 18:58 
Generalobtain SID Pin
rohit.dhamija6-Feb-03 0:53
rohit.dhamija6-Feb-03 0:53 
GeneralRe: obtain SID Pin
Iain Clarke, Warrior Programmer6-Feb-03 6:02
Iain Clarke, Warrior Programmer6-Feb-03 6:02 
QuestionWinXp machine, but WINVER macro is 0x400 ?? Pin
CEx6-Feb-03 0:42
CEx6-Feb-03 0:42 
AnswerRe: WinXp machine, but WINVER macro is 0x400 ?? Pin
HENDRIK R6-Feb-03 1:10
HENDRIK R6-Feb-03 1:10 
AnswerRe: WinXp machine, but WINVER macro is 0x400 ?? Pin
KarstenK6-Feb-03 3:09
mveKarstenK6-Feb-03 3:09 
Generalabout zip file and jar file, urgent Pin
includeh106-Feb-03 0:26
includeh106-Feb-03 0:26 
GeneralRe: about zip file and jar file, urgent Pin
-Dy6-Feb-03 0:50
-Dy6-Feb-03 0:50 
GeneralRe: about zip file and jar file, urgent Pin
Ambit6-Feb-03 1:43
Ambit6-Feb-03 1:43 
GeneralRe: about zip file and jar file, urgent Pin
Mike Nordell6-Feb-03 4:11
Mike Nordell6-Feb-03 4:11 
GeneralRe: about zip file and jar file, urgent Pin
includeh106-Feb-03 5:23
includeh106-Feb-03 5:23 
GeneralRe: about zip file and jar file, urgent Pin
Mike Nordell7-Feb-03 3:55
Mike Nordell7-Feb-03 3:55 
GeneralDefault CD Player??. Pin
Demian Panello6-Feb-03 0:11
Demian Panello6-Feb-03 0:11 
GeneralExecuting the container Pin
-Dy5-Feb-03 23:21
-Dy5-Feb-03 23:21 
GeneralHtmlView, multiframe Pin
jeremysay5-Feb-03 23:21
jeremysay5-Feb-03 23:21 
GeneralRe: HtmlView, multiframe Pin
HENDRIK R6-Feb-03 0:55
HENDRIK R6-Feb-03 0:55 
GeneralRe: HtmlView, multiframe Pin
jeremysay6-Feb-03 2:04
jeremysay6-Feb-03 2:04 

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.