Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Regarding assignment to struct Date: Sun, 04 May 2025 07:49:15 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: <868qnc77o4.fsf@linuxsc.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 04 May 2025 16:49:16 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f2e2a4892b4200c8deca4768c4473856"; logging-data="2179137"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pnGivYv/8VyCXlyCZrSrKTM0Rgl/BaNg=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:cI97DIImBR2grRwr9pMxIpcIeJ4= sha1:Lp6Kv7jaaLKNbwNUJDw5fwKfzXE= Bytes: 2117 Lew Pitcher writes: > 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? The style is unorthodox, but the code is understandable. Also it is both legal and well-defined, back to and including C90.