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: Difference between these pointer syntaxes Date: Thu, 18 Aug 2016 13:22:52 -0700 Organization: None to speak of Lines: 64 Message-ID: References: <4628cd2d-9333-4be6-943a-eb593c5c4c12@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="26067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18D1QgXSbHc8dftWqzuwHOw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:5uEAGB4DFV93V1FnEQRNfX/xes0= sha1:oS6+Yh/213eUjFdlua0+NTOPj3o= Xref: csiph.com comp.lang.c:92478 Les Cargill writes: > Keith Thompson wrote: [...] >> But the "arrays are really pointers" misconception is a *bad* >> abstraction. >> >> Perhaps the worst problem with it (and I blame the design of C for this) >> is that you can do a lot of stuff based on the assumption that arrays >> and pointers are interchangeable. But sooner or later you'll run into >> things that can't be explained under that model. `sizeof array_object` >> yields the size of *something*, but what exactly, if there's no such >> thing as an array? If `ptr = array;` is valid, then `ptr = &array;` >> is a compile-time error -- but why? >> > > But we all understand ( after a learning period ) that "sizeof()" > information is lost. And I understand *when and why* it's lost -- but only because I clearly distinguish between arrays and pointers. [...] >>>> Can you explain the behavior of `sizeof` while pretending that there's >>>> no such thing as an array? (Array type, array object, array whatever.) >>>> >>>> Can you explain what >>>> >>>> int arr[10]; >>>> >>>> does in terms of pointers, without references to arrays? Can you >>>> explain the result of `sizeof arr`? [SNIP] >> Sorry, that didn't help at all. Can you explain it in terms of the >> specific example I used? >> >> int arr[10]; >> > > Sure! > > alternate declaration 1: > > int arr[] = static_allocate(10,); // no initial values. > > alternate declaration 2: > > int *arr = static_allocate(10,); // no initial values. > > The only difference then between them is that > "arr = " is a diagnostic. I asked you to explain the result of `sizeof arr`. I don't see how your static_allocate() thingie (not sure what it is) helps with that. [...] -- 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"