Quantcast
Viewing all articles
Browse latest Browse all 4867

General • How to report compile time values ?

I am wanting to report the compile time values of A, B and C as set in the below by way of example -

Code:

#define XTR(x) # x#define STR(x) XTR(x)enum {  A,    // 0  B,    // 1};#define C  2#pragma message "A = " STR(A)#pragma message "B = " STR(B)#pragma message "C = " STR(C)
But that doesn't work for the 'enum' defined values, only '#define', both GCC for Pi and for Pico ...

Code:

x.c:12:9: note: #pragma message: A = Ax.c:13:9: note: #pragma message: B = Bx.c:14:9: note: #pragma message: C = 2
I am trying to port code similar to below but far more complicated -

Code:

#if WANT_A  #if WANT_B    #define A     0    #define B     1    #define TOTAL 2  #else    #define A     0    #define TOTAL 1  #endif#else  #define   TOTAL 0#endif
To a far more elegant -

Code:

enum {  #if WANT_A    A,    #if WANT_B      B,    #endif  #endif  TOTAL};
And, to make sure my porting is correct, that I haven't messed-up any conditionals, I'd like to know and prove that 'TOTAL' has the correct value, same as it was in the non-ported code. How should I do that ?

Statistics: Posted by hippy — Sat Mar 16, 2024 6:46 pm



Viewing all articles
Browse latest Browse all 4867

Trending Articles