Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: What is a `**ppEnum`? Date: Thu, 17 Nov 2022 10:17:43 -0800 Organization: None to speak of Lines: 42 Message-ID: <87mt8pmomw.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="bb8b7969f2cb7f9b9861eb04b7ed4835"; logging-data="2839375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4dLdl3CPlzRybCvnopAPq" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:0/28EDZmKsJODUTxUXSqdY/Mk2U= sha1:nfCfhnrMEzern6r1hJVEohDNmOE= Xref: csiph.com comp.lang.c++:87435 Juha Nieminen writes: > T 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 */