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: C Programming Tutorial on Youtube Date: Sat, 15 Oct 2016 12:47:53 -0700 Organization: None to speak of Lines: 61 Message-ID: References: <8be0cdbe-c2f4-42ec-b6a7-e9a154981718@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="d0721e8dde95c3bcc5de2a1c92f543fd"; logging-data="2955"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZLjf+exHSr5t2A+hAUBjk" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:soPnaTz+7rkH6h32XwvifFEnSZ4= sha1:XKdFjOLBVhPXgD/GOG/cW3LcRYg= Xref: csiph.com comp.lang.c:94871 BartC writes: > On 15/10/2016 03:09, Richard Damon wrote: >> On 10/11/16 9:55 PM, Keith Thompson wrote: >>> Malcolm McLean writes: >>>> int buff[1024]; >>>> >>>> buff is a constant pointer to a buffer (which C mis-terms an "array") >>>> which contains enough space for 1024 integers. Except there's a little >>>> syntactical quirk. But that can be ignored for now. >>> >>> If you're trying to demonstrate the idea of being deliberate misleading, >>> well done. >>> >> >> IF you want a constant pointer to a 'buffer' of ints: >> >> >> int buffer[1024][ >> >> int * const pointer = buffer; >> >> >> pointer now IS a constant pointer to the array buffer. accessable int by >> int. > > No. 'pointer' is set up as the address of a location that /contains/ a > pointer to buffer. It is not a pointer to buffer. (When both are at file > scope.) `pointer` is a pointer object whose value points to the initial element of the array object `buffer`. One can *informally* think of it as pointing to `buffer`, but it's better to be precise, especially in this kind of discussion. [...] > The nearest thing to a constant pointer to the buffer is 'buffer' > itself. But in the language, you have to express it as the name of an > array. I think this is what I said much further up the thread. It's just > a question of whether it's allowable to think of it as a constant > pointer to a block of integers rather than an array of integers. No, you don't have to express it that way. When used in a context where array-to-pointer conversion takes place, the expression `buffer` is equivalent to `&buffer[0]`. If you want to explicitly refer to a pointer to the initial element of `buffer`, `&buffer[0]` is less ambiguous than `buffer`. > I think this is what I said much further up the thread. It's just > a question of whether it's allowable to think of it as a constant > pointer to a block of integers rather than an array of integers. You're allowed to think anything you like, but if you think `pointer` points to the array object `buffer`, you're incorrect, or at least imprecise. -- 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"