Tool/software:
Given this "simple" snipped of code:
if ( meta_data_size_announced != (uint16_t)(MIN_META_DATA_SIZE + name_size_from_meta_data() + custom_meta_data_size_from_meta_data() ) )
{
return reset_state();
}
Why is the cast (to uint16_t one the right hand side of the != operator) above necessary? I have the value of 31 on the left and on the right side of the != operator and would expect that the expression yields false, even without that cast.
MIN_META_DATA_SIZE is defined as:
#define MIN_META_DATA_SIZE ( \
1 /* Firmware Name Size */ \
+ 1 /* Firmware Major Version */ \
+ 1 /* Firmware Minor Version */ \
+ 2 /* Firmware Type */ \
+ 2 /* Hardware Type */ \
+ 8 /* Device ID */ \
+ 8 /* Flags / Reserved */ \
+ 4 /* Custom Meta Data Size */ )
`name_size_from_meta_data()` and `custom_meta_data_size_from_meta_data()` are declared as follows:
static size_t name_size_from_meta_data(void); static uint32_t custom_meta_data_size_from_meta_data(void);
`meta_data_size_announced` is a static variable of type uint16_t. `name_size_from_meta_data` returns 4 in the given case and `custom_meta_data_size_from_meta_data()` returns 0.
Beside adding the cast above, I found a few other methods to get the desired result:
- Disable optimization (instead of --opt_level=4)
- Removing the call to `custom_meta_data_size_from_meta_data()`
- Using a different compiler like clang
I see this effect, with the 20.2.2 and 22.6.0 Version of the TI compiler.
Thanks in advance and best regards,
Torsten