Is calculation done at compile time or run time?

 

I have defined a few macros for constant values. Some macros are dependent to another for example

#define x 14
#define y x+7
#define z y*5

So I wonder these values are going to be calculated at the run time? or they are going to be calculated when compiling and the final values will be put to the ex5 file.


Also what about a for loops?

for(int i=0;i<10;i+=2)
  {
   ObjectSetInteger(0,"OBJNAME"+i,OBJPROP_YDISTANCE,YPOS+2);
  }

// or
ObjectSetInteger(0,"OBJNAME0",OBJPROP_YDISTANCE,YPOS+2);
ObjectSetInteger(0,"OBJNAME2",OBJPROP_YDISTANCE,YPOS+2);
ObjectSetInteger(0,"OBJNAME4",OBJPROP_YDISTANCE,YPOS+2);
ObjectSetInteger(0,"OBJNAME6",OBJPROP_YDISTANCE,YPOS+2);
ObjectSetInteger(0,"OBJNAME8",OBJPROP_YDISTANCE,YPOS+2);
 
pavelion: I have defined a few macros for constant values. Some macros are dependent to another for example.So I wonder these values are going to be calculated at the run time? or they are going to be calculated when compiling and the final values will be put to the ex5 file. Also what about a for loops?

The macros are calculated at compile time but only for literal constants, not variables.

As for the loop, that is at runtime, but there may be some compiler optimisations being done under the hood, for which we are not aware.

 
pavelion:

I have defined a few macros for constant values. Some macros are dependent to another for example

So I wonder these values are going to be calculated at the run time? or they are going to be calculated when compiling and the final values will be put to the ex5 file.


Also what about a for loops?

You should use brackets on your macro expansions. You might get wrong results else.