1

I'm trying to show this in C (gcc, C11)

#define xstr(a) _str(a)
#define _str(a) #a

#pragma message "System clock = " xstr(SYS_CLOCK)

Now the SYS_CLOCK is a macro, computing from values of prescalers, dividers, etc
But the message is not calculated

#pragma message: System clock= ((8000000u/4)*50)/4

Which is better than nothing :) but actually, I'd be very happy if I can show 25000000 Hz.

Can be done with some preprocesor magic?

Thanks,

yo3hcv
  • 1,531
  • 2
  • 17
  • 27
  • Most probably it can't be done, because all preprocessors I know do no calculations. Did you look into the standard to see what is required? And additionally, what does the GCC documentation say? If its preprocessor would do calculations, I'd expect that it's documented. – the busybee Jul 26 '20 at 11:23
  • See also https://stackoverflow.com/questions/1560357/can-the-c-preprocessor-perform-integer-arithmetic – Jiří Baum Jul 26 '20 at 12:11

1 Answers1

0

Preprocessor does not calculate any values (except needed by the #if). It is done during the compilation. Everything is done at the token level.

0___________
  • 60,014
  • 4
  • 34
  • 74