[Tarantool-patches] [PATCH v4 1/4] util: introduce strlcpy helper

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Dec 15 01:54:18 MSK 2020


On 11.12.2020 12:38, Cyrill Gorcunov wrote:
> On Fri, Dec 11, 2020 at 02:07:53PM +0300, Serge Petrenko wrote:
> ...
>>>
>>> n.b. You know every time I see `if (x != [0|NULL])` statement
>>> it driving me nuts: the language standart is pretty clear for
>>> `if ()` statement and explains how it is evaluated and I always
>>> wonder who exactly invented this explisit test for non-zero/nil?!
>>> Now *every* if statement requires 5 additional symbols for simply
>>> nothing :( I suspect the person who started to use this form
>>> simply was not aware of the language standart.
>>
>> I guess it's more about code readability rather than producing a
>> correct expression according to the standard.
> 
> Hardly. I suspect it was due to lack of understanding how code
> compiles and evaluates, and being nonfamiliar with standarts ;)

I don't think it is because of not knowing basics of C. Everyone
knows that you can use anything as a boolean expression and it will
be evaluated to != 0/NULL. Even first year students.

We don't use that intentionally. Because code with implicit boolean
checks is harder to read. You can't deduct type of a variable in 'if'
when you don't use '!' for bools, != 0 for numbers, != NULL for
pointers. Also implicit boolean cast sometimes looks confusing. For
example '!strcmp(a, b)' seems like a != b, but it means the opposite.


More information about the Tarantool-patches mailing list