Re: [PATCH 35/35] qsort.3: Use sizeof consistently

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

 



On 9/5/20 5:27 PM, Michael Kerrisk (man-pages) wrote:> On 9/5/20 4:20
PM, Alejandro Colomar wrote:
>> Use ``sizeof`` consistently through all the examples in the following
>> way:
>>
>> - Use the name of the variable instead of its type as argument for
>>   ``sizeof``.
>>
>> 	Rationale:
>>
https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory
>>
>> Signed-off-by: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx>
>
> I'm not convinced about this one. Do you really think it
> improves readability? I kinda feel that it does not.

Well, I have two different ideas for this one.
In terms of readability, `char *` might seem clearer.
In terms of preventing bugs, `argv[0]` seems safer.
For real code I would use the latter.  For the man, I have doubts.

Follow your intuition :)

>
> Thanks,
>
> Michael
>
>> ---
>>  man3/qsort.3 | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/man3/qsort.3 b/man3/qsort.3
>> index b49c2a9d3..e1af43cf0 100644
>> --- a/man3/qsort.3
>> +++ b/man3/qsort.3
>> @@ -150,7 +150,7 @@ main(int argc, char *argv[])
>>          exit(EXIT_FAILURE);
>>      }
>>
>> -    qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
>> +    qsort(&argv[1], argc \- 1, sizeof(argv[0]), cmpstringp);
>>
>>      for (j = 1; j < argc; j++)
>>          puts(argv[j]);
>>
>
>



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux