The directive #define in itself carries out only text substitution, but not prediction of expressions with constants. That is, if you correct the PRIMERF declaration to the correct one (you have a comma missing):
#define PRIMERF(V1,V2) (V1+2)*(V2+2)
then at the stage of processing by the preprocessor PRIMERF(2,3) will turn into (2+2)*(3+2) .
Predicting a constant expression can be done at compile time, but this is not guaranteed. Let's say Visual C ++ performs it, including when optimization is disabled:
#include <stdio.h> #include <stdlib.h> #define PRIMERP 315 #define PRIMERF(V1,V2)(V1+2)*(V2+2) int main(int argc, char **argv) { int i = PRIMERP; int j = PRIMERF(2,3); printf("%d %d",i,j); ; getchar(); return 0; } /* Disassembly: _main: push ebp mov ebp,esp sub esp,8 push esi mov dword ptr [j],0CCCCCCCCh mov dword ptr [i],0CCCCCCCCh mov dword ptr [i],13Bh // int i = PRIMERP; mov dword ptr [j],14h // int j = PRIMERF(2,3); mov esi,esp mov eax,dword ptr [j] push eax mov ecx,dword ptr [i] push ecx push 0F05858h call dword ptr ds:[0F092C0h] // printf("%d %d",i,j); add esp,0Ch cmp esi,esp call _RTC_CheckEsp (0F01220h) mov esi,esp call dword ptr ds:[0F092C8h] // getchar(); cmp esi,esp call _RTC_CheckEsp (0F01220h) xor eax,eax pop esi add esp,8 cmp ebp,esp call _RTC_CheckEsp (0F01220h) mov esp,ebp pop ebp ret */
14h is the precomputed value of the expression (20 in hexadecimal)
#definereplaces one piece of text with another. In this example, in the first case, after the replacement, it will really beint i = 315;however,int j = (2+2)*(3+2);in the second. - VTT