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
As already noted, the Prepocessot just does text substitution - it does not evaluate anything.
Most toolsets have an option to view the preprocessor output; for Keil C51, it is PREPRINT: http://www.keil.com/support/man/docs/c51/c51_preprint.htm
See also: http://www.keil.com/support/man/docs/uv4/uv4_dg_listing.htm
But it is the Compiler - not the preprocessor - which evaluates (or may evaluate) constant expressions.
AFAIK, The only way to see what the Compiler has done is to look at the generated assembly:
http://www.keil.com/support/man/docs/c51/c51_code.htm http://www.keil.com/support/man/docs/c51/c51_cm_lstfile.htm
Do you think that statement is 100% accurate?
Consider:
#include <stdio.h> void main(void) { #if (1+1)==2 printf("(1+1)==2 : Accuracy of advice is important!\n"); #else printf("(1+1)!=2 : Accuracy of advice is not important!\n"); #endif }
Which text do you think will be printed?
OK, "the Macro pocessor just does text substitution - it does not evaluate anything"
Macro pocessor
Not a good day for accuracy.
It's a fair cop!