From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Beginning Ada Programming, by Andrew T. Shvets (2020) Date: Sat, 18 Apr 2020 19:23:19 -0700 Organization: None to speak of Message-ID: <87y2qsdxig.fsf@nosuchdomain.example.com> References: <87muca3vgd.fsf@nightsong.com> <57d49047-0a61-4d13-8822-d004732a3acc@googlegroups.com> <007895f7-b923-4267-9801-d0caaaa30838@googlegroups.com> <41ef6a77-3b14-43ff-b6ae-510000a33ad4@googlegroups.com> <9f2bfb05-fb5e-45cf-909e-53629b939da3@googlegroups.com> <229f9564-4f23-4b12-bea9-518ceda86a09@googlegroups.com> <9ecb00e7-e677-4cec-80f7-3484116c871a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="b749a550d867a16e61e4817403566579"; logging-data="14642"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jyFSXyTxLoLXQA0ctVwgS" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:apVNyVdOT4xnqPS9tgXpxeqwOhc= sha1:kr7ryA5fRIjMameD1kFrnRTU0vE= Xref: reader01.eternal-september.org comp.lang.ada:58416 Date: 2020-04-18T19:23:19-07:00 List-Id: "Luke A. Guest" writes: > On 18/04/2020 22:54, cantanima.perry@gmail.com wrote: >> On Saturday, April 18, 2020 at 12:59:38 PM UTC-5, Jere wrote: >>> Actually it does work on low level arrays in C++. It doesn't work >>> on pointers to array elements however, which people often confuse >>> with arrays (that's how people most often pass them to functions, >>> but there are other methods). >> >> I didn't realize C++ had progressed to tracking how long a low-level >> array is, but in retrospect it's come along so much in terms of what >> you can do at compile-time that I should have tested before >> commenting. Thank you. Both C and C++ have always tracked how long a low-level array is. There's no built-in operator that gives you the number of element in an array, but "sizeof arr / sizeof arr[0]" is a common idiom. Except for VLAs (variable-length arrays, supported in C99, optional in C11, not supported in C++), the number of elements in an array always a compile-time constant. What neither language can do is determine the length of an array given a pointer to its initial element, which is how raw arrays are usually manipulated in C and low-level C++. (Not to be confused with std::array, which is a C++ container class added in C++11.) > I don't think it can, I think the new iterator for loops are for stl > containers only. I could be wrong though. You can iterate over a C++ array if you have visibility to the array object itself. Very often you don't have that visibility. Which is why C++ has std::vector, std::array, et al. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */