Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: structs passed by copy Date: Mon, 06 Mar 2023 09:32:52 -0800 Organization: A noiseless patient Spider Lines: 28 Message-ID: <86mt4p9457.fsf@linuxsc.com> References: <76ec6d87-0f5d-4671-b4c8-7023e3da787an@googlegroups.com> <87o7pzdcmj.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="08553e16564f4582e6ecc9eb792331ba"; logging-data="9709"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fFgXcNbsxQyuCTXMuCxO0g5IYU4p255c=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:LEgyBD/KuUgN/bFTBTrkeL7f3Rk= sha1:QCSbhcEz/Gynpzez45GFxepOsO0= Xref: csiph.com comp.lang.c:169540 Keith Thompson writes: > Jorgen Grahn writes: > >> On Fri, 2023-01-20, Thiago Adams wrote: > > [...] > >>> Do you have structs passed by copy in your code? >> >> Yes, a lot. I don't write C these days, but last time I got to design >> new C code, in 2014 or so, I used the feature heavily, to get some >> properties I'd normally get from C++. I think call by value is one of >> the great things about the C family of languages. >> >>> Could it be replaced by const * ? >> >> No. > > Could you expand on that? I would think that any instance of passing a > struct by copy could be straightforwardly replaced by passing it by > const*, assuming your able to modify both the caller and the callee. > I'm not suggesting that this *should* be done, but you seem to be saying > that it *couldn't*. (I could be a good idea for large structs.) It *could* be done, but it's clunky for struct arguments that are not lvalues, as for example a struct returned by a function call, or a struct that comes out of a ?: expression.