| Deutsch English Français Italiano |
|
<vv474a$2pg8e$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: That depends... (Was: Regarding assignment to struct) Date: Sat, 3 May 2025 00:47:06 -0400 Organization: A noiseless patient Spider Lines: 21 Message-ID: <vv474a$2pg8e$1@dont-email.me> References: <vv338b$16oam$1@dont-email.me> <51ba1k5h5lkj75qvfuj0ferlddpb6bi0n8@4ax.com> <vv3art$2ku6u$1@news.xmission.com> <vv3qkc$2b7nd$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Sat, 03 May 2025 06:47:15 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e3ea90e84671a8e1bf204aa19b4ecb98"; logging-data="2933006"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18avpZIUoEN8TYYKkqA6WjeDlPIqLDaZ4E=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:IOII9wqm7UmD3HTX8NVrupdlBfk= In-Reply-To: <vv3qkc$2b7nd$1@dont-email.me> Content-Language: en-US On 5/2/25 21:13, Lew Pitcher wrote: .... > But... I remembered this (apparently) seldom-used feature of being able > to pass a struct by value up and down the chain (down, as a function > argument, up as a function return value). As I've not done this before, > and I've not /seen/ it done in other peoples code, I wonder how viable > a solution it might be. > > If it is legal, then why isn't it used more often? Is it a readability/ > maintainability issue, or is it something else? The most basic reason is that a pointer to a struct is smaller than most structs (particularly one that contains 5 items). In addition, passing it up and down the chain nominally requires making multiple copies of it, one in each function that takes it as an argument, and another copy when you store the return value - though compilers can optimize some of that away. Changes made to one copy will not be made to the other copies, which is very often not what you want. The cases where I've seen the approach used the most successfully were to implement things like complex numbers (before they were added to C99).