0

I have C program which uses several static variables.

#define A 5
#define B 1
#define C 60

Now, I want to determine which values I should give to these macros to get the best results from my algorithm.

To find these values I just want to run my algorithm for each value I want to test.

To do so I have to change the value of these macros on runtime.

Is there a way to do so? (Honestly, since these are static I don't expect so) Alternative: is there another (better) way to achieve my testing goals?

Ricardo
  • 335
  • 1
  • 4
  • 13

1 Answers1

2

No, macros have no "values". They expand to whatever you set them and that's it.

The expansion, substitutes their occurrance literaly. They are not expressions and hence are not evaluated, compilers can give you as output the preprocessed code, if you try that you will see that this

int x = A;

will be replaced with (using the definitions you posted)

int x = 5;

before compilation, so it's impossible to alter the value at runtime; i.e. After Compilation.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97