bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: enum vs int and API/ABI compatibility


From: Simon Josefsson
Subject: Re: enum vs int and API/ABI compatibility
Date: Thu, 20 Oct 2011 22:02:21 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.90 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Hi Simon,
>
>> silence C++ warnings ...
>> 
>>   typedef enum
>>   {
>> ...
>>   } Idna_rc;
>> ...
>>   extern IDNAPI const char *idna_strerror (Idna_rc rc);
>> 
>> ... allows future C++ code to be warning free.
>
> It was said that the root problem is that your idna_* functions
> return an 'int', but idna_strerror takes an Idna_rc. This is
> inconsistent.

Right.

> There are three ways to fix this in a way that gets rid of the C++ warnings:
>
> 1) Change the return types from 'int' to 'Idna_rc'. Keep the enum as it is.

Given that there appears to be environments where compilers pick a type
smaller than int for small enums (the Idna_rc enum is small), this seems
to imply an ABI break.

> 2) Change the argument type of idna_strerror to 'int'.

Which also seems to potentially break ABI.

> Change the enum from
>
>      typedef enum {
>        ...
>        IDNA_ICONV_ERROR = 9,
>        ...
>      } Idna_rc;
>
>    to
>
>      typedef int Idna_rc;
>      #ifdef __cplusplus
>      /* In C++ we avoid macros.  */
>      ...
>      const int IDNA_ICONV_ERROR = 9;
>      ...
>      #else
>      ...
>      #define IDNA_ICONV_ERROR 9
>      ...
>      #endif

Why is this second part needed?

> 3) Keep the inconsistency as it is for C, but fix it for C++ only.
>    Change the enum from
>
>      typedef enum {
>        ...
>        IDNA_ICONV_ERROR = 9,
>        ...
>      } Idna_rc;
>
>    to
>
>      #ifdef __cplusplus
>      typedef int Idna_rc;
>      /* In C++ we avoid macros.  */
>      ...
>      const int IDNA_ICONV_ERROR = 9;
>      ...
>      #else
>      typedef enum {
>        ...
>        IDNA_ICONV_ERROR = 9,
>        ...
>      } Idna_rc;
>      #endif

I'm starting to consider this option.  It is a rather ugly solution to
silence a compiler warning though.

Thanks,
/Simon



reply via email to

[Prev in Thread] Current Thread [Next in Thread]