Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Help on this typedef Date: Fri, 19 May 2017 09:51:54 -0700 Organization: None to speak of Lines: 63 Message-ID: References: <8ad1e08b-bdf9-4baa-a8b4-63bf48fb3e3d@googlegroups.com> <7828b0dd-de46-40a2-9636-81117d1f17f6@googlegroups.com> <799899ab-ccf3-49a4-a928-d405dc142fff@googlegroups.com> <87fug2yond.fsf@bsb.me.uk> <431ea3d0-2d91-40b9-8988-868be7f0382e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="189d31b8aa2df37c9a5da9ba095e96a2"; logging-data="14760"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gBFQqGyz6cIB6aAUv5Lz7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:k1ie6ds6Z3ldf3yCRXoVkNLl+Jw= sha1:jC+LorG+WwoIsvRklydEWV5NL+A= Xref: csiph.com comp.lang.c:110388 joel.rees@gmail.com writes: > On Friday, May 19, 2017 at 4:02:24 AM UTC+9, Ben Bacarisse wrote: [...] >> No. char x[] and char *x mean the same thing in a parameter declaration >> but not elsewhere, and definitely not in a struct! > > Yeah, parameters. You could increment a parameter declared that way as > if it were a pointer, but you couldn't assign a struct member delared > empty. I keep forgetting. A parameter declared that way *is* a pointer. For example, this: void func(int param[42]); really means this: void func(int *param); `param` simply is not an array. (And the 42 is quietly ignored, which is unfortunate.) > I have this vague memory that the reasoning behind the array size 1 hack > was to avoid conflation with the tendency to assume a size left out was > a pointer. There was a time, very early in the design of C, when [] was used to declare pointers, and defining an array object would create an implicit pointer object pointing to the array's initial element. Dennis Ritchie changed that because it didn't work when structures have members that are arrays. For example, if you have a structure like this: struct foo { int arr[10]; }; and the definition of arr creates a pointer, then copying the structure would copy the pointer, and the copy would point back to the original object. This change was made some time around the transition from "NB" to C. See , and search for "Embryonic C". Unfortunately, the myth that C arrays are really just pointers has survived long past the time when there was any truth to it. Suggested reading: Section 6 of the comp.lang.c FAQ, . (And then the rest of it.) [...] > And I guess I should acknowledge that Keith and others were trying to > point out that the standard had flip-flopped on which hack to use for > indeterminant, that is, flexible, arrays while I was busy working with > other languages in the previous decade. I wouldn't say the standard flip-flopped. The C89/C90 standard doesn't mention the struct hack. C programmers invented it, and it happened to work. C99 introduced flexible array members as a standard-endorsed way to achieve the same effect while avoiding undefined behavior. -- 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"