nasa / osal

The Core Flight System (cFS) Operating System Abstraction Layer (OSAL)
Apache License 2.0
557 stars 218 forks source link

Many compilation warnings when compiling under lp64 data model with -Wconversion option #1462

Open GFWisshit opened 6 months ago

GFWisshit commented 6 months ago

Hi guys. osal/src/os/shared/inc\os-shared-idmap.h:257:38: warning: implicit conversion loses integer precision: 'unsigned long' to 'osal_objtype_t' (aka 'unsigned int') [-Wshorten-64-to-32] return (OS_ObjectIdToInteger(id) >> OS_OBJECT_TYPE_SHIFT);

image image The return value type of OS_ObjectIdToInteger is unsigned long and the return type of OS_ObjectIdToType_Impl is uint32_t, which causes an implicit conversion and causes the compiler to complain.Will this warning be fixed?

jphickey commented 6 months ago

Certainly there is a preference for making the code compile cleanly without warnings, but in my experience most/all of the "conversion" warnings are just a nuisance. My recommendation would be to simply turn off the conversion warning (-Wno-conversion) for the reason that it just creates a lot of false-positive noise.

This one looks like it could be worked around with a cast. But there is no actual problem as all the values being used are within the range of "unsigned int" (unsigned long was only used here for consistency with the %lx printf conversion specifier). So while the compiler does see a loss of precision, its not actually an issue at all.