From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755696AbcEaWFU (ORCPT ); Tue, 31 May 2016 18:05:20 -0400 Received: from science.sciencehorizons.net ([71.41.210.147]:24859 "HELO ns.sciencehorizons.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with SMTP id S1752788AbcEaWFS (ORCPT ); Tue, 31 May 2016 18:05:18 -0400 Date: 31 May 2016 18:05:15 -0400 Message-ID: <20160531220515.17294.qmail@ns.sciencehorizons.net> From: "George Spelvin" To: andriy.shevchenko@linux.intel.com, joe@perches.com, linux@sciencehorizons.net Subject: Re: [PATCH] lib/uuid.c: eliminate uuid_[bl]e_index arrays Cc: akpm@linux-foundation.org, bjorn@mork.no, linux-kernel@vger.kernel.org, tytso@mit.edu In-Reply-To: <1464730604.14627.66.camel@perches.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Functions with sized array arguments are generally undesired. > > Linus once wrote: (http://comments.gmane.org/gmane.linux.kernel/2031400) > > array arguments in C don't > actually exist. Sadly, compilers accept it for various bad historical > reasons, and silently turn it into just a pointer argument. There are > arguments for them, but they are from weak minds. > > Perhaps this would be better using simple pointers and without the __ > > static int __uuid_to_bin(const char *uuid, u8 *b, const u8 *si) I haven't looked up the full original discussion to see if this is a point on which I disagree with Linus, but I find it useful for documentation: this is not just a pointer to "some" bytes, this is a pointer to [LENGTH] bytes. It's a reminder to the caller that they'd better pass in a buffer of the required size. Obviosuly, it makes no actual difference to the compiler. C99 actually has a way to say this explicitly to the compiler, but the syntax is ugly: static int __uuid_to_bin(const char uuid[static 36], __u8 b[static 16], const u8 si[static 16]) (This includes the effect of __attribute__((nonnull)).) Further discussion at https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html https://stackoverflow.com/questions/3430315/what-is-the-purpose-of-static-keyword-in-array-parameter-of-function-like-char (FWIW, another two style points which I disagre with Linus about are that I don't mind "sizeof variable" without parens, and that I don't mind using a bare "0" for a null pointer. More substantially, I like "bool" a lot more than Linus does.)