Deutsch   English   Français   Italiano  
<3fd0dce206153c0d2dc7cf26291165c3381e9bc2@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!news.quux.org!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: Richard Damon <richard@damon-family.org>
Newsgroups: comp.lang.c
Subject: Re: Regarding assignment to struct
Date: Sat, 3 May 2025 21:42:37 -0400
Organization: i2pn2 (i2pn.org)
Message-ID: <3fd0dce206153c0d2dc7cf26291165c3381e9bc2@i2pn2.org>
References: <vv338b$16oam$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 4 May 2025 01:44:56 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="3031557"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <vv338b$16oam$1@dont-email.me>
X-Spam-Checker-Version: SpamAssassin 4.0.0

On 5/2/25 2:34 PM, Lew Pitcher wrote:
> Back in the days of K&R, Kernighan and Ritchie published an addendum
> to the "C Reference Manual" titled "Recent Changes to C" (November 1978)
> in which they detailed some differences in the C language post "The
> C Programming Language".
> 
> The first difference they noted was that
>    "Structures may be assigned, passed as arguments to functions, and
>     returned by functions."
> 
>  From what I can see of the ISO C standards, the current C language
> has kept these these features. However, I don't see many C projects
> using them.
> 
> I have a project in which these capabilities might come in handy; has
> anyone had experience with assigning to structures, passing them as
> arguments to functions, and/or having a function return a structure?
> 
> Would code like
>    struct ab {
>      int a;
>      char *b;
>    } result, function(void);
> 
>    if ((result = function()).a == 10) puts(result.b);
> 
> be understandable, or even legal?
> 
> 

I will say that I have used the feature, but in very limited conditions, 
mostly where the structure is no bigger than one or two typical words.

It could be a structure with a bitfield to make accesses clearer than 
low level masking, or for a "point" with x and y tied into one object.

Bigger than that, and you likely want to pass the object by address, not 
by value, passing just a pointer to it.