We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Thanks for the response. I realize how the macro is expanded however I am pretty sure that the constant expression that it results in is evaluated and the result is what is replaced. For example it will not try to actually compute floating point calculation at run time. It will not link in floating point libs etc.
#define FOO(bar) (unsigned char)((double)(bar)*0.75)
void someFunc(void){ unsigned char a; .... a=FOO(100); .... }
At compile time, FOO(100); will be replaced with the constant 75 and the line in the function will be a=75; In the same way as if you write a= (1<<5); this doesn't result in several left shift operations being generated. It results at compile time to be 32; Maybe this is done as an optimizing step by the C-compiler and not the preprocessor but I have used other tools that will show the what the final value substituted is. Maybe there is no such feature in the C51 toolset. I have historically found it to be a useful thing to have available.
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!
It is.
The Keil C51 Manual calls it, "Constant Folding":
http://www.keil.com/support/man/docs/c51/c51_optimize.htm
is quite simple WORD temp_variable = AXX*BYY/CCC;
and have a pek in the debugger, then remove temp_variable
Erik