This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: extern const initialized warns in C


On 25 January 2018 at 12:29, Jonathan Wakely wrote:
> On 25 January 2018 at 12:27, Georg-Johann Lay wrote:
>> On 22.01.2018 16:20, Jonathan Wakely wrote:
>>>
>>> On 21 January 2018 at 12:08, Georg-Johann Lay wrote:
>>>>
>>>> Jay K schrieb:
>>>>>
>>>>>
>>>>> extern const int foo = 123;
>>>>>
>>>>> Why does this warn?
>>>>> This is a valid portable form, with the same meaning
>>>>> across all compilers, and, importantly, portably
>>>>> to C and C++.
>>>>
>>>>
>>>> I also wondered about this.
>>>>
>>>> In C99 §6.9.2 "External object definitions" there's actually
>>>> the following example in clause 4:
>>>>
>>>> extern int i3 = 3; // definition, external linkage
>>>
>>>
>>> That's a different case. There's no advantage to the 'extern' here,
>>> because the code means the same thing in C and C++ without the
>>> 'extern', so just leave it out.
>>
>>
>> I'd rather like to know why GCC is throwing a warning here.
>>
>> It's clear how to hack the C source, but that's a different point.
>>
>> It's just the case that I don't see any problem with that construct,
>> and it was worth an explicit example in the standard.  Or is it
>> common practice to warn constructs that are "no advantage"?
>
> Read https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45977 (as already
> stated earlier in the thread).

Also, examples in the standard exist to show what is technically
valid, not what is good coding style.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]