Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #87435

Re: What is a `**ppEnum`?

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: What is a `**ppEnum`?
Date 2022-11-17 10:17 -0800
Organization None to speak of
Message-ID <87mt8pmomw.fsf@nosuchdomain.example.com> (permalink)
References (3 earlier) <ff8b48f4-e2f9-4ae9-865d-7e657f4ac1c0n@googlegroups.com> <tkt73c$1o60i$2@dont-email.me> <tl2bj1$1en4$1@gioia.aioe.org> <tl3t9g$2f98u$1@dont-email.me> <tl4r60$1026$1@gioia.aioe.org>

Show all headers | View raw


Juha Nieminen <nospam@thanks.invalid> writes:
> T <T@invalid.invalid> wrote:
>> The only thing I am not following, is how do I know the
>> length of each item in the array and how many items are
>> in the array.
>
> The size (in bytes, if that's what you mean) of each element in the
> array is just the sizeof the element type. If you have a 'Type*' pointer,
> then the size of each element in the array is sizeof(Type).
>
> A pointer does not carry with itself any information about what it's
> pointing to (other than the type of that thing). In other words, you
> cannot know, from the pointer alone, whether it's pointing to a single
> value or to an array, or what the size of that array is.

A (valid non-null) pointer to FOO points to a single object (not value)
of type FOO.  It never points to an array, unless FOO happens to be an
array type.  The single FOO object that it points to may or may not be
an element of an array of FOO (and if it's really just a single object,
it can be treated as the sole element of a 1-element array of FOO).

The think you cannot know is the size of the array of which the
pointed-to FOO object may be an element.

It's not uncommon to refer informally to a pointer to the initial
element of an array as a pointer to the array, but pointers to arrays
are a distinct thing.

> So to answer your question about how you know how many items there are
> in the array: You don't.
>
> You need to pass the number of elements in the array as a separate value
> alongside the pointer.
>
> (To make this easier you could eg. create a struct that has the pointer
> and a 'std::size_t' member variable telling how many elements there
> are in the array pointed to by the pointer.)

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 00:39 -0800
  Re: What is a `**ppEnum`? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-14 01:29 -0800
    Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 01:46 -0800
      Re: What is a `**ppEnum`? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-14 01:52 -0800
        Re: What is a `**ppEnum`? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-14 01:55 -0800
      Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-14 02:30 -0800
        Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 02:38 -0800
          Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-14 02:48 -0800
  Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-14 01:39 -0800
    Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 01:48 -0800
      Re: What is a `**ppEnum`? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-14 02:01 -0800
      Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-14 02:33 -0800
        Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 02:59 -0800
          Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-14 03:33 -0800
            Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 11:10 -0800
          Re: What is a `**ppEnum`? Juha Nieminen <nospam@thanks.invalid> - 2022-11-16 09:47 +0000
            Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-16 15:55 -0800
              Re: What is a `**ppEnum`? scott@slp53.sl.home (Scott Lurndal) - 2022-11-17 00:19 +0000
              Re: What is a `**ppEnum`? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2022-11-17 01:21 +0000
                Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-16 18:01 -0800
                Re: What is a `**ppEnum`? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-16 18:40 -0800
                Re: What is a `**ppEnum`? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2022-11-17 04:18 +0000
              Re: What is a `**ppEnum`? Juha Nieminen <nospam@thanks.invalid> - 2022-11-17 08:25 +0000
                Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-17 00:31 -0800
                Re: What is a `**ppEnum`? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-17 10:17 -0800
              Re: What is a `**ppEnum`? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-17 13:03 +0000
                Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-17 10:28 -0800
          Re: What is a `**ppEnum`? Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2022-11-17 03:36 +0000
            Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-16 20:57 -0800
  Re: What is a `**ppEnum`? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-14 14:34 +0100
    Re: What is a `**ppEnum`? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-14 14:44 +0100
    Re: What is a `**ppEnum`? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-14 09:12 -0800
    Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-14 11:02 -0800
      Re: What is a `**ppEnum`? Ralf Fassel <ralfixx@gmx.de> - 2022-11-15 10:17 +0100
        Re: What is a `**ppEnum`? Öö Tiib <ootiib@hot.ee> - 2022-11-15 04:24 -0800
      Re: What is a `**ppEnum`? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-15 14:04 +0100
        Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-15 08:28 -0800
          Re: What is a `**ppEnum`? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-17 16:21 +0100
            Re: What is a `**ppEnum`? T <T@invalid.invalid> - 2022-11-17 16:39 -0800
              Re: What is a `**ppEnum`? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-19 14:16 +0100

csiph-web