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: Bruno Haible
Subject: Re: enum vs int and API/ABI compatibility
Date: Wed, 19 Oct 2011 22:11:24 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

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.

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.

2) Change the argument type of idna_strerror to 'int'. 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

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


Bruno
-- 
In memoriam Jerzy Popiełuszko <http://en.wikipedia.org/wiki/Jerzy_Popiełuszko>



reply via email to

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