Re: [RFC PATCH 1/2] Replace memset(0) with static initialization where possible

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

 



Shawn O. Pearce wrote:
> Brandon Casey <casey@xxxxxxxxxxxxxxx> wrote:
>> Is there interest in a patch like this?
> 
> I think this is not a worthwhile change.
>  
>> "Possible" benefits:
>>
>>   1) more concise, so it improves readability in most cases
> 
> I'm not sure.
> 
> Maybe I'm just too used to reading memset(&foo, 0, sizeof(foo)),

Well, I don't have to get the sizeof(foo) part right if I use {0,}.

> but {{0},} seems very difficult to read.

It wouldn't be the first usage in the git source.

>>   2) gives compiler more flexibility when optimizing
> 
> Shouldn't a good C compiler notice something like a memset and inline
> it when possible?  They already can inline strlen on a constant.

I'm sure most of them do.

>> Drawbacks:
>>
>>   1) many lines touched for no functional change
> 
> That's a pretty big drawback.
> 
> What happens when a struct gets a struct as its first member?
> Do all the {0,} inits for it have to change to {{0,},} ?

yes, if you don't want compiler warnings.

-brandon

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux