gcc gets in the way of writing C that is also C++ wrt const

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

 




I try to write C code that is valid C++ and has the same meaning in C++.


const int a = 1;


does not have the same meaning in C and C++.


So I would write:


extern const int a = 1;


which does have the same meaning in both, but for some reason gcc doesn't quite like this and gives a warning.


I end up doing:


/* const is extern const in C, but static const in C++,
* but gcc gives a warning for the correct portable form "extern const" */
#if defined(__cplusplus) || !defined(__GNUC__)
#define EXTERN_CONST extern const
#else
#define EXTERN_CONST const
#endif


EXTERN_CONST int a = 1;



which is just lame.


- Jay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux