2026-06-05 2:24 AM
Hello,
I am using STM32CubeIDE (eclipse) and was wondering if it is possible to get the constant calculated value of a macro.
For example
#define A 1
#define B 2
#define R A+B // R is now 3
#if R > 2
#warning R is greater
#else
#warning R is less 2
#endifI can only see 1+2 in the macroexpansion. But clearly the IDE has calculated the value and can evaluate the #if ... #else and gray out the unused part. So how can i access this calculated value?
2026-06-05 3:49 AM
@Ozone wrote:the preprocessor ... uses different datatypes and ranges than the compiler
@Nickelgrass more details here.
2026-06-05 4:39 AM
Thanks for all the replies. I solved it by simply putting a little python script in the prebuild step that parses and calculates the values and displays them in the console. Would be nice though to have such a functionality build in. Case closed.
2026-06-05 4:53 AM - edited 2026-06-05 4:54 AM
@Nickelgrass wrote:Case closed.
To do that, please mark the solution on the post which provided the answer - not this one!
BTW:
I wrote:Or write some test code that will do it for you ...
The Compiler Explorer could be useful for that - you can copy & paste the full macro expansion from the IDE into it.
I had a quick google to see if there's a site where you can just paste-in a C expression and have it evaluated - didn't find one.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.