How to calculate and SHOW value of #define macro VStudio

1

I know how to show expanded macro in C. However, I am interested in how to show a calculated value of a macro.

Precompiler definitely calculates macro values in order to do #if(a>b) statement:

#define STRINGIFY(s) XSTRINGIFY(s)
#define XSTRINGIFY(s) #s
#define ONE_BYTE_Tx_Time 11
#define NUM_OF_BYTES     16
#define BUSY_TIME        132
#define TOTAL_TIME       300
#define AVAIL_TIME       (TOTAL_TIME-BUSY_TIME)
#define RESP_TIME        (ONE_BYTE_Tx_Time * NUM_OF_BYTES)

#pragma message ("AVAIL_TIME =" STRINGIFY(AVAIL_TIME))
#pragma message ("RESP_TIME =" STRINGIFY(RESP_TIME))

#if (AVAIL_TIME <= RESP_TIME)
  #error "not enough time"
#endif

The output during compilation is:

    AVAIL_TIME =(300-132)
    RESP_TIME =(11 * 16)
    fatal error C1189: #error :  "not enough time"

So, precompiler had calculated two integers, compared them and outputted an error.

My question is: how to show actual RESULT of macro calculation during compilation?, i.e.

   AVAIL_TIME = 168 // which is (300-132)
   RESP_TIME = 176  // which is (11 * 16)

The formulas expansion can be rather complicated, so it is useful to see result during compilation, without running of the code:

   AVAIL_TIME_in_SysTicks =(((75000000/1000000) * (1000000/2500)) - 2 * ((((75000000/1000000) * ((1000000000/900000) + 1)*(10 + 0x00000000/0x00000008) + 2)/1000) * 16)) 

Thanks, Igor

macros
precompiler
asked on Stack Overflow Aug 24, 2018 by Igor K

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0