Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: James Kuyper Newsgroups: comp.std.c Subject: Re: Initial draft proposal: "Safe arrays and pointers for C" Date: Thu, 16 Aug 2012 13:28:20 -0400 Organization: A noiseless patient Spider Lines: 42 Message-ID: <502D2DB4.1000404@verizon.net> References: <502949DA.9000604@animats.com> <50297066.1010202@loria.fr> <502A9EEB.6050309@verizon.net> <502ACC52.1060808@verizon.net> <502BF4CA.1040304@verizon.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="d8fef572ea43a1acd556896aa70d63af"; logging-data="17408"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18egIDkcGRWm3FEv6sNqpL51U79rheii3M=" User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: Cancel-Lock: sha1:eq0jj7M8202eMeShztOUdnW4Dbg= Xref: csiph.com comp.std.c:1500 On 08/16/2012 12:57 PM, John Nagle wrote: > On 8/16/2012 4:39 AM, Derek M. Jones wrote: >> All, >> >> On 15/08/2012 21:00, John Nagle wrote: >> ... >>> Occurrences of "sizeof" on fixed length arrays also appear to be >>> rare to nonexistent in the corpus of C code known to Google Code Search. >> >> According to my measurements 12% of sizeof operands have an >> array type. > > How many of those are VLAs, and how many are VLA array parameters? > > That's the big question here. This sub-thread traces back to my non-serious proposal that the standard be modified to explicitly specify that the value of sizeof be determined prior the adjustment that converts a parameter declared as an array into a parameter that's actually a pointer. The associated quantitative issue is how much code would be broken by such a change. Given a function defined as follows: int func( size_t n, double left[n], double (*middle)[n], double right[4]) { With the standard as currently written, sizeof(left)==sizeof(double*), and sizeof(right)==sizeof(double*). With my non-serious proposal, sizeof(left)==n*sizeof(double), sizeof(right)==4*sizeof(double). Any such code which uses sizeof(left), or sizeof(right), expecting it to give the currently correct value, would break if that proposal were adopted. Note that "middle" is the only argument with a variably-modified type ("left" and right are both ordinary pointers), yet it's unaffected by this proposal. sizeof(middle)==sizeof(double(*)[n]), whether or not that proposal were approved. Therefore, VLAs are NOT the big question, at least not in this sub-thread.