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.
Hi folks, I have tried the following source code and it seemed not behaving what I was expected
#define Const1 (10) #define Const2 (Const1/4096) #define Base (2850) unsigned int g_wData; float g_fA = Base; float g_fB = Base; u8 IsChanged(void) { g_fA = Base + (Const2 *g_wData); /*if the two value are the same,just return 0*/ /*else return 1 and assign the new value to...*/ if(g_fA == g_fB ) { return (0); } g_fB = g_fA ; return (1); }
The values you are using in the macro definitions are integers and thus, when used, Const2 yields a subexpression value of zero and g_fA will always equal g_fB. Change:
#define Const1 (10)
#define Const1 (10.0)
#define Const2 (Const1/4096)
#define Const2 (Const1/4096.0)