Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail From: =?UTF-8?B?SGFucy1CZXJuaGFyZCBCcsO2a2Vy?= Newsgroups: comp.std.c Subject: Re: Initial draft proposal: "Safe arrays and pointers for C" Date: Wed, 15 Aug 2012 00:37:06 +0200 Lines: 52 Message-ID: References: <502949DA.9000604@animats.com> <50297066.1010202@loria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.dfncis.de rTrhYIbBtb9nMRDOURsgKQ/ds0v45/HOS2VoL8qTlMmJq9z7FirbmrkECPHG0bYxukA76p29za Cancel-Lock: sha1:RiJdjGnyDARz5zthEJzFuviQuQ0= User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20120604 Thunderbird/13.0 In-Reply-To: Xref: csiph.com comp.std.c:1448 On 14.08.2012 22:24, John Nagle wrote: > On 8/14/2012 12:09 PM, Hans-Bernhard Bröker wrote: >> On 14.08.2012 20:20, John Nagle wrote: >>> On 8/13/2012 10:23 PM, Keith Thompson wrote: >> >>>> C does not have parameters of array type. "a" is not an array, it's a >>>> pointer. > > It's a fully qualified array pointer, It is not, and it cannot be, because such a thing as an "array pointer" does not exist in C. There are pointers to arrays (the abovementioned 'a' is one), and there arrays of pointers, but no "array pointers". Nor did "fully qualified" have any meaning in this language, last I looked. That's C++ speak. I will ignore and snip all references to this imaginary entity from here on. > which has most of the behaviors of an array. Not more so than any other pointer would. Which makes sense, since it _is_ a pointer. > True. And here's the mess it creates, even for a fixed size array: > > typedef double mat4[4][4]; > void fn1(mat4 m0) > { mat4 m1; > size_t s0 = sizeof(m0); > size_t s1 = sizeof(m1); > printf("Size of m0 is %d.\nSize of m1 is %d", s0, s1); > } > > Size of m0 is 4. > Size of m1 is 128 > > This is not good. That's only a mess if you want it to be one. >>> It's certainly desirable to be able to obtain the size of an array >>> when the language knows it. >> >> But in the case at hand the language _doesn't_ know it. > > Array size information is used for subscript calculations for > multidimensional array parameters. That only considers the size for the inner dimensions. The one we're looking at here is the outermost dimension --- and that's neither used nor needed for that.