This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: extern const (Was: Re: [gcc-in-cxx]: patches from multi-target-4_4-branch)
- From: Gabriel Dos Reis <dosreis at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: Joern Rennecke <amylaar at spamcop dot net>, gcc at gcc dot gnu dot org
- Date: Mon, 25 May 2009 11:40:17 -0500
- Subject: Re: extern const (Was: Re: [gcc-in-cxx]: patches from multi-target-4_4-branch)
- References: <20090429064704.r7nzgfg18okko8s8-nzlynne@webmail.spamcop.net> <m363gn1qui.fsf@google.com> <20090524121328.5bxlsmbf4cgos440-nzlynne@webmail.spamcop.net> <m3tz3anfh8.fsf@google.com> <20090524232321.v5panilqo84484cg-nzlynne@webmail.spamcop.net> <m34ov9zunt.fsf@google.com>
- Reply-to: gdr at integrable-solutions dot net
On Sun, May 24, 2009 at 11:13 PM, Ian Lance Taylor <iant@google.com> wrote:
> Joern Rennecke <amylaar@spamcop.net> writes:
>
>> Quoting Ian Lance Taylor <iant@google.com>:
>>> Joern Rennecke <amylaar@spamcop.net> writes:
>>>> ? ? * config/sh/sh.c (sh_attribute_table): Use extern in forward
>>>> ? ? declaration.
>>>> Common issue with declaring/defining const variables in C++.
>>>
>>> I've been doing this as
>>>
>>> #ifdef __cplusplus
>>> extern
>>> #endif
>>
>> These #ifdefs sprinkled over the code are awkward. ?Could we use a #define
>> for this? ?E.g. put in system.h
>> #ifdef __cplusplus
>> #define CONST_VAR_DECL extern const
>> #else
>> #define CONST_VAR_DECL const
>> #endif
>
> Yes, that is certainly the way to go if it is in fact not safe to use
> "extern const int i = 1;" for all C compilers. ?I hadn't planned to deal
> with this issue yet, but since you bring it up, we should decide whether
> that construct is safe, or whether we need the macro.
>
> Ian
>
I believe
extenr const' should be pretty safe in any C90 compiler.
Do we know a compiler that does not handle that correctly?