Hello guys, i came about a something strange to me while programming and Debugging some c-Code with AVR-Studio 7. I was trying to watch the value of an Expression while Debugging, but i get the message "unknown identifier". The Expression is defined as follows: #define THRESH1 (uint16_t) ((uint32_t)1024*(500 + 1*800)/5000) does anyone has an idea, why i can't watch the value of this constant? By the way, i've tried declaring it localy or global, but i still get the same message. Moreover, i tried with the following Expression: const uint16_t thresh1_3 = (uint16_t) ((uint32_t)1024*(500 + 3*800)/5000); but the watch variable only works when it is a local constant, not global. Does anyone has a hint there too? I also deactivated optimizations too but it doesn't seem to help. Thanks and Cheers Paul
Paul wrote: > Hello guys, > i came about a something strange to me while programming and Debugging > some c-Code with AVR-Studio 7. I was trying to watch the value of an > Expression while Debugging, but i get the message "unknown identifier". > The Expression is defined as follows: > > #define THRESH1 (uint16_t) ((uint32_t)1024*(500 + 1*800)/5000) > > does anyone has an idea, why i can't watch the value of this constant? Because it is a preprocessor macro. At runtime, it doesn't exist in that form anymore. A macro is similar to your editors search/replace functions, just with the difference that the text to be replaced is specified within the processed file itself. > By the way, i've tried declaring it localy or global, but i still get > the same message. There is no such thing as "locally" or "gobally" with respect to macros. > Moreover, i tried with the following Expression: > > const uint16_t thresh1_3 = (uint16_t) ((uint32_t)1024*(500 + > 3*800)/5000); > > but the watch variable only works when it is a local constant, not > global. It might get optimized out by the compiler. Does the symbol thresh1_3 exist in the generated executable?
> Because it is a preprocessor macro. At runtime, it doesn't exist in that > form anymore. A macro is similar to your editors search/replace > functions, just with the difference that the text to be replaced is > specified within the processed file itself. Thank you, that is what i tought too, anyways I want to use the calculated constant to test for a certain condition. So I expected I could actually see what value was calculated:
1 | #define THRESH1_1 (uint16_t) ((uint32_t)1024*(500 + 1*800)/5000)
|
2 | #define THRESH1_2 (uint16_t) ((uint32_t)1024*(500 + 2*800)/5000)
|
3 | #define THRESH1_3 (uint16_t) ((uint32_t)1024*(500 + 3*800)/5000)
|
4 | #define THRESH1_4 (uint16_t) ((uint32_t)1024*(500 + 4*800)/5000)
|
5 | if(u16_adValue0 <= THRESH1_1) |
6 | {
|
7 | ... something; |
8 | }
|
9 | else if(u16_adValue0 <= THRESH1_2) |
10 | {
|
11 | ... some other thing; |
12 | }
|
and so on... > It might get optimized out by the compiler. Does the symbol thresh1_3 > exist in the generated executable? I did deactivate optimizations, but it didn't Change anything. I don't really understand what you mean with generated executable because i'm flashing the Code directly in a microcontroller (ATmega32u4)
If your macro is expected to represent just a numerical expression (macros could actually represent anything) then you could directly assign it to a variable for debugging purposes. If you make that variable volatile then it won't be optimized away and you can watch it in the debugger to confirm that your macro expands and evaluates to the correct value.
1 | #define FOO_BAR (uint16_t) ((uint32_t)1024*(500 + 1*800)/5000)
|
2 | |
3 | // fixme: remove this after you know its evaluated correctly
|
4 | volatile uint16_t debug_foo_bar = FOO_BAR; |
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.