Different values compiling for what I believe should be the same code
I ran across a very strange issue with how numbers are interpreted using #define with and without a leading zero.
See the 2 below examples and the comment I put next to each:
#define LED_DRIVER_BOARD_TYPE 0270 // This compiles as 0x00B8 which is not correct
#define LED_DRIVER_BOARD_TYPE 270 // This compiles as 0x010E, which is correct
Why would these not be the same number? I tried this in version 3.7.7 and 4.1.0 and they both the same. Is this a compiler bug I stumbled on or is this something with C that I am not aware of?
Thanks
Steve
-
This is correct behaviour, a leading zero indicates an octal literal in C/C++ ( http://en.cppreference.com/w/cpp/language/integer_literal ).
Please sign in to leave a comment.
Comments
3 comments