Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Bart Newsgroups: comp.lang.c Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?= =?UTF-8?B?IGEgIm5ldyIgQyA/?= Date: Sat, 17 Aug 2024 11:38:05 +0100 Organization: A noiseless patient Spider Lines: 38 Message-ID: References: <20240711115418.00001cdf@yahoo.com> <20240712154252.00005c2f@yahoo.com> <86o7717jj1.fsf@linuxsc.com> <20240717163457.000067bb@yahoo.com> <86a5hep45h.fsf@linuxsc.com> <87y14xsvnh.fsf@bsb.me.uk> <87sev5s51s.fsf@bsb.me.uk> <87jzgge4hd.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 17 Aug 2024 12:38:04 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2b4731a8bc26cc69ac4ef4f27bf4b89c"; logging-data="1973944"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ayVW/OGdaRVLJT6Ll9/Qc" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:m7L1ARgWRXVhuPrdtDPn3ZyLgN8= Content-Language: en-GB In-Reply-To: <87jzgge4hd.fsf@nosuchdomain.example.com> Bytes: 2614 On 16/08/2024 18:56, Keith Thompson wrote: > David Brown writes: > [...] >> In C++, you can't pass arrays as parameters at all - the language >> inherited C's handling of arrays. You can, of course, pass objects of >> std::array<> type by value or by reference, just like any other class >> types. > > #include > > typedef int array42[42]; > > void func(array42& param) { > assert(sizeof param == 42 * sizeof(int)); > } > > int main() { > array42 arg = { }; > func(arg); > } This works in C too. You don't need by-reference parameters, but you do need to switch sizeof to work directly on the type: #include typedef int array42[42]; void func(array42 param) { assert(sizeof(array42) == 42 * sizeof(int)); } int main() { array42 arg = {0}; func(arg); }