Definition of enum does not conform to ISO C standard

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Definition of enum does not conform to ISO C standard

Postby CismonX » Wed Jun 30, 2021 11:48 pm

When using the CEF C API, I got the following warnings during compilation:

Code: Select all
/path/to/cef_90.6.6/include/internal/cef_types.h:1016:3: warning: ISO C restricts enumerator values to range of 'int' (4294967295 is too large) [-Wpedantic]
  DRAG_OPERATION_EVERY = UINT_MAX
  ^                      ~~~~~~~~
/path/to/cef_90.6.6/include/internal/cef_types.h:1257:3: warning: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) [-Wpedantic]
  TT_SERVER_REDIRECT_FLAG = 0x80000000,
  ^                         ~~~~~~~~~~
/path/to/cef_90.6.6/include/internal/cef_types.h:1262:3: warning: ISO C restricts enumerator values to range of 'int' (3221225472 is too large) [-Wpedantic]
  TT_IS_REDIRECT_MASK = 0xC0000000,
  ^                     ~~~~~~~~~~
/path/to/cef_90.6.6/include/internal/cef_types.h:1267:3: warning: ISO C restricts enumerator values to range of 'int' (4294967040 is too large) [-Wpedantic]
  TT_QUALIFIER_MASK = 0xFFFFFF00,
  ^                   ~~~~~~~~~~


According to ISO/IEC 9899:1999:

The expression that defines the value of an enumeration constant shall be an integer
constant expression that has a value representable as an int.


So unless on platforms where an int is 64-bit wide (unfortunately not the case for either Windows, Linux or macOS), whenever we try something like:

Code: Select all
cef_transition_type_t transition_type = TT_IS_REDIRECT_MASK;


We are converting a 64-bit integer to an 32-bit one (assuming LLP64 or LP64) that cannot represent the value, which is implementation-defined behaviour.

Perhaps the bitmasks could be redesigned? So that the code can be standard conformant, and some potention problems can be avoided.
CismonX
Newbie
 
Posts: 1
Joined: Wed Jun 30, 2021 10:47 pm

Re: Definition of enum does not conform to ISO C standard

Postby magreenblatt » Thu Jul 01, 2021 11:00 am

There seem to be mixed opinions on this warning. Some sources suggest that the max unsigned hex literal value should be 0x7FFFFFFF. Others suggest that this should be handled just fine by GCC as a extension to the C language (being an extension, it is warned by -pedantic).

What compiler, version and architecture are you using? Are you seeing actual bad implementation-specific behavior?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 38 guests