This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Displaying result of Macro evaluation

is there an easy way to see what the result is from something like the following...

#define ADC_MIN 1.8
#define ADC_MAX 2.4
#define ADC_MAX_VAL 255
#define ADC_LSB (double)(( ADC_MAX - ADC_MIN)/(double)ADC_MAX_VAL)
#define ADC_GAIN 0.5

#define ADC_VAL(x) ((((double)(v)) - ADC_MIN + (double)(ADC_GAIN)*ADC_LSB)/ADC_LSB)

#define WHAT_IS_THIS_VAL (unsigned char) ADC_VAL(100)

Of course I can crunch it all by hand but it would be nice to see what the preprocessor evaluates this to. I could go to where this is used and see what the value is but ideally I would like a list of symbols that contains the macro name and the value that is substituted for that macro.

I saw in doc the DIR command but wasn't able to get the result I wanted and I only see actual memory variables in the symbol list.

Thanks for any help in advance

Parents
  • Of course I can crunch it all by hand but it would be nice to see what the preprocessor evaluates this to.

    No. It would be anything but nice. Because the preprocessor does nothing like the kind of "evaluation" you appear to expect. It just replasces text by other text. In particular, it performs none of the math in those lines.

    To see what the preprocessor actually makes of your code, you should just run it through the preprocessor and look --- every C compiler worth having offers a way to do that. It's an exercise worth doing every once in a while, and sometimes it's an absolutely necessary test to understand why something you tried to do with the preprocessor just didn't work.

    You'll have to modify your example, though, because as is, the preprocessor will compile it to effectively nothing at all. But if you finish it with an invocation of the final macro, you will get something like this:

    (unsigned char) ((((double)(v)) - 1.8 + (double)(0.5)*(double)(( 2.4 - 1.8)/(double)255))/(double)(( 2.4 - 1.8)/(double)255))
    

Reply
  • Of course I can crunch it all by hand but it would be nice to see what the preprocessor evaluates this to.

    No. It would be anything but nice. Because the preprocessor does nothing like the kind of "evaluation" you appear to expect. It just replasces text by other text. In particular, it performs none of the math in those lines.

    To see what the preprocessor actually makes of your code, you should just run it through the preprocessor and look --- every C compiler worth having offers a way to do that. It's an exercise worth doing every once in a while, and sometimes it's an absolutely necessary test to understand why something you tried to do with the preprocessor just didn't work.

    You'll have to modify your example, though, because as is, the preprocessor will compile it to effectively nothing at all. But if you finish it with an invocation of the final macro, you will get something like this:

    (unsigned char) ((((double)(v)) - 1.8 + (double)(0.5)*(double)(( 2.4 - 1.8)/(double)255))/(double)(( 2.4 - 1.8)/(double)255))
    

Children