dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
646 stars 182 forks source link

Fix some warnings on GCC 7.5 #152

Closed mcrlc closed 4 years ago

mcrlc commented 4 years ago

When building with GCC 7.5 and the following flags -Wsign-conversion -Wconversion these lines produced warnings. For some reason GCC didn't like the UL literal only in multiplications...

151

mikkelfj commented 4 years ago

I don't understand why you can't cast *(char *) to uint32_t - what does the error say?

As to the constant suffix, it is better to use UINT32_C(value) since U and UL are platform specific.

mikkelfj commented 4 years ago

The header needs

#ifndef UINT8_MAX
#include <stdint.h>
#endif

in order to use UINT32_C, although it is already included via flatcc_flatbuffers.h via flatcc_types.h, but that depends on the order of include files.

mcrlc commented 4 years ago

Regarding the char to uint32_t conversion, I actually found out an open bug in the GCC project for this type of conversions: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49626 As for the literal suffix, I'll probably fix them tomorrow.

Thanks for the quick turnaround :)

mikkelfj commented 4 years ago

I'll try make a commit based on clangs -Wsign-conversion warnings. I'm not sure I want to deal with GCC bugs from 2011, that are still open. If you can't cast properly, all bets are off.

mcrlc commented 4 years ago

I agree, it's probably safe to suppress this warning on GCC.

mikkelfj commented 4 years ago

For reference, the proposed changes were committed directly to master branch along with many others. See also related issue #151.