Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Copy array with small changes Date: Mon, 12 Mar 2018 09:08:01 -0700 Organization: None to speak of Lines: 46 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="877122f47cb3293e34ad9ed0b03f90bc"; logging-data="6599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18waA3OZO1mpJTHyyGb+eAM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:51NnxYgpfRUZgi1D/l/4ZxI6a8E= sha1:BgSPabtDd9OG5jvqsus2rxFUf5I= Xref: csiph.com comp.lang.c:127684 Spiros Bousbouras writes: > On Mon, 12 Mar 2018 10:35:32 +0000 > bartc wrote: >> On 11/03/2018 22:13, Spiros Bousbouras wrote: [...] >> > void update_array(const int * const arr , const size_t n , >> > const size_t zi , const size_t zj , const int val) >> > >> > Actually something like arrsz is a better name than n. >> >> No, this suggests array size which in C usually means byte-size, not >> number of elements. > > You have any statistics to back this up ? I always use it to mean number > of elements. I have no statistics, but since the sizeof operator yields its operand's size in bytes, I tend to assume that "size" is in bytes. For the number of elements in an array, I might use "length" (or "len" if I'm being terse). [...] >> Well, it /had/ been short until you introduced all these consts! (Is >> there really a benefit from declaring individual int parameters as const?) > > It remains short. I thought the const declarations might help with > optimisation but the only way to tell is to test. I'd be surprised if adding "const" to an int parameter declaration would help optimization. A parameter is a local object, so if the compiler is doing the analysis necessary for optimization, it should already know that the object is never modified. I like to use "const" on (non-parameter) object declarations unless the object actually needs to be modified, more for the benefit of the reader than for the benefit of the compiler. I'm not sure what the best policy is for parameters. My own style is admittedly inconsistent. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"