[sheepdog] [PATCH] sheep: remove unnecessary extern keyword

Liu Yuan namei.unix at gmail.com
Thu Jan 24 09:03:43 CET 2013


On 01/24/2013 03:54 PM, MORITA Kazutaka wrote:
> At Thu, 24 Jan 2013 15:43:30 +0800,
> Liu Yuan wrote:
>>
>> On 01/24/2013 03:24 PM, Liu Yuan wrote:
>>> On 01/24/2013 03:18 PM, MORITA Kazutaka wrote:
>>>> Is removing extern from global variables really correct?.  It means
>>>> that the variables are defined in all .c files which include the
>>>> header.  Actually, GCC complains the error when the global variables
>>>> are initialized.
>>>
>>> Umm, I used sed to replace all the 'extern' and fixed some warnings, and
>>> yeah,global variables have this problem. My mistake.
>>>
>>
>> But my GCC (4.6.3) don't complain on the missing extern for global
>> variables. I guess new GCC might have some magic to handle this
>> duplicate definition of global variables. Anyway, I've posted a patch to
>> fix it.
> 
> So even if we define the same global name in different sources, GCC
> doesn't complain it?  I think It can easily cause bugs and looks like
> we need a mechanism to detect it.
> 

I double checked it on my box, it seems that GCC don't complain it at
all for such case:

 A.c: int test;
 B.c: int test = 1;

But complains for:
 A.c: int test = 1;
 B.c: int test = 2;


How about your environment? I guess both variable and functions are
default as 'extern', then it seems that is syntax safe to move 'extern'
for variable and functions. And multiple definition will be dected by
GCC at link phase.

Thanks,
Yuan




More information about the sheepdog mailing list