From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id CB5F345C304 for ; Tue, 15 Dec 2020 01:54:20 +0300 (MSK) From: Vladislav Shpilevoy References: <20201210161832.729439-1-gorcunov@gmail.com> <20201210161832.729439-2-gorcunov@gmail.com> <02c6bfc0-ceb1-c1bc-5d8b-2450dbc082bc@tarantool.org> <20201211100408.GC544004@grain> <20201211113812.GE544004@grain> Message-ID: <16ff8d4c-c57b-f9a6-ee98-ddca191b3475@tarantool.org> Date: Mon, 14 Dec 2020 23:54:18 +0100 MIME-Version: 1.0 In-Reply-To: <20201211113812.GE544004@grain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH v4 1/4] util: introduce strlcpy helper List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Cyrill Gorcunov , Serge Petrenko Cc: Mons Anderson , tml 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.