Preprocessor arithmetic

Im not sure how preprocessor arithmetic works, but if i had this for example:

#define SCREEN_SCALE ( ( ( SCREEN_WIDTH / 640 ) + ( SCREEN_HEIGHT / 480 ) ) / 2 )

Every time i use SCREEN_SCALE, is it using the result of whats there, which is precalculated OR
is it just replacing SCREEN_SCALE with the above expression?
Before compilation starts all occurrences of SCREEN_SCALE that follows will be replaced by ( ( ( SCREEN_WIDTH / 640 ) + ( SCREEN_HEIGHT / 480 ) ) / 2 ) (if SCREEN_WIDTH and SCREEN_HEIGHT are also macros they will be replaced too).

The compiler will most likely compute the result at compile time so it doesn't actually slow things down during runtime but why don't you just use the const keyword to define constants?
 
const int SCREEN_SCALE = (SCREEN_WIDTH / 640 + SCREEN_HEIGHT / 480) / 2;
Thats what i did after i posted this actually, i just wasnt sure because ive never done anything like this. Usually i onlu use defines because i only have one number.

Anyway, cheers
Topic archived. No new replies allowed.