On Wed, Apr 29, 2009 at 7:13 AM, Manuel López-Ibáñez
<lopeziba...@gmail.com> wrote:

>>> * In C a const variable which is neither "extern" nor "static" is
>>>   visible outside of the current translation unit.  In C++ it is not,
>>>   without an explicit "extern" declaration.  I'm not sure how best to
>>>   handle this with -Wc++-compat, since C does not permit initializing an
>>>   "extern const" variable.
>>
>> C does permit it; there's a warning, not a pedwarn.  Add an option to
>> disable this warning (at least where "const" is used)?
>
> In any case, -Wc++-compat should warn about the difference in
> behaviour, shouldn't it?
>
> I see the current code already handles this somehow:
>
>          /* It is fine to have 'extern const' when compiling at C
>              and C++ intersection.  */
>           if (!(warn_cxx_compat && constp))
>             warning (0, "%qs initialized and declared %<extern%>", name);
>
> BTW, why is this warned about?

I believe I'm the author of that code.

We had had this debate a couple of years back, when I had more resources
to work on GCC.  At the time, I was doing an incremental version of the amazing
job Ian just accomplished and the CPP component had the construct that
declared a variable as const but did not initialize it, and did not contain
the `extern' specifier.  That in C++ meant that the variable has an internal
linkage -- but in C, the variable would have an external linkage.
So, to write the code that meant the same thing in C and in C++, an
'extern' specifier is needed.

The C people (I bellieve) at the time felt strongly that if not -Wc++-compat
it probably should be warned about (because it is not "typical" C).

-- Gaby

Reply via email to