Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #393106 > unrolled thread
| Started by | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| First post | 2025-05-02 18:34 +0000 |
| Last post | 2025-05-04 14:09 -0700 |
| Articles | 9 on this page of 109 — 20 participants |
Back to article view | Back to comp.lang.c
Regarding assignment to struct Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-05-02 18:34 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-02 13:17 -0700
Re: Regarding assignment to struct Barry Schwarz <schwarzb@delq.com> - 2025-05-02 13:35 -0700
That depends... (Was: Regarding assignment to struct) gazelle@shell.xmission.com (Kenny McCormack) - 2025-05-02 20:44 +0000
Re: That depends... (Was: Regarding assignment to struct) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-05-03 01:13 +0000
Re: That depends... (Was: Regarding assignment to struct) Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-03 02:28 +0000
Re: That depends... (Was: Regarding assignment to struct) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-05-03 06:17 +0200
Re: That depends... (Was: Regarding assignment to struct) Kaz Kylheku <643-408-1753@kylheku.com> - 2025-05-03 04:31 +0000
Re: That depends... (Was: Regarding assignment to struct) Kaz Kylheku <643-408-1753@kylheku.com> - 2025-05-03 05:11 +0000
Re: That depends... (Was: Regarding assignment to struct) Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-05-05 12:30 +0200
Re: That depends... (Was: Regarding assignment to struct) Kaz Kylheku <643-408-1753@kylheku.com> - 2025-05-05 18:47 +0000
Re: That depends... (Was: Regarding assignment to struct) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-04 11:05 -0700
Re: That depends... (Was: Regarding assignment to struct) James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-05-03 00:47 -0400
Re: That depends... (Was: Regarding assignment to struct) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-04 10:59 -0700
Re: That depends... (Was: Regarding assignment to struct) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-05-04 18:16 +0000
Re: Regarding assignment to struct antispam@fricas.org (Waldek Hebisch) - 2025-05-02 21:35 +0000
Re: Regarding assignment to struct Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2025-05-03 01:43 +0000
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-03 01:14 -0700
Re: Regarding assignment to struct Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-03 22:46 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-03 17:37 -0700
Re: Regarding assignment to struct James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-05-03 23:38 -0400
Re: Regarding assignment to struct gazelle@shell.xmission.com (Kenny McCormack) - 2025-05-04 09:25 +0000
Re: Regarding assignment to struct scott@slp53.sl.home (Scott Lurndal) - 2025-05-04 14:27 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-04 18:45 +0200
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-04 13:20 -0700
Re: Regarding assignment to struct scott@slp53.sl.home (Scott Lurndal) - 2025-05-05 00:41 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-04 18:42 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 21:57 -0700
Re: Regarding assignment to struct James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-05-04 21:08 -0400
Re: Regarding assignment to struct Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-03 22:47 +0000
Re: Regarding assignment to struct Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-03 22:46 +0000
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-04 06:48 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-04 22:22 -0700
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-05 11:12 +0300
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-05 01:29 -0700
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-05 12:01 +0300
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 07:14 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-05 08:45 -0700
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-05 20:20 +0300
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 22:26 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:11 -0700
Re: Regarding assignment to struct James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-05-29 12:57 -0400
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 13:27 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 17:04 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 17:53 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-01 18:54 -0800
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-01 19:36 -0800
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-06 11:35 +0200
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:19 -0700
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-29 21:05 +0200
Re: Regarding assignment to struct antispam@fricas.org (Waldek Hebisch) - 2025-05-06 17:36 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-06 20:46 +0200
Re: Regarding assignment to struct scott@slp53.sl.home (Scott Lurndal) - 2025-05-06 19:22 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-07 09:37 +0200
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:49 -0700
Re: Regarding assignment to struct Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-05-29 16:33 +0200
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-29 21:20 +0200
Re: Regarding assignment to struct scott@slp53.sl.home (Scott Lurndal) - 2025-05-29 21:15 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-29 14:54 -0700
Re: Regarding assignment to struct scott@slp53.sl.home (Scott Lurndal) - 2025-05-30 14:29 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-30 10:50 +0200
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-22 04:40 -0800
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-06 13:06 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:21 -0700
Re: Regarding assignment to struct Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-05-29 16:43 +0200
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-06-06 17:44 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:14 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-29 13:56 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 07:03 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 01:26 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-05 10:14 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-08 12:45 -0700
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-08 22:20 +0200
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 01:34 -0700
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-05 12:03 +0300
Re: Regarding assignment to struct gazelle@shell.xmission.com (Kenny McCormack) - 2025-05-05 11:30 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 13:32 -0700
Re: Regarding assignment to struct Kaz Kylheku <643-408-1753@kylheku.com> - 2025-05-05 21:10 +0000
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 22:57 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 22:40 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 06:34 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 13:43 -0700
Re: Regarding assignment to struct Nick Bowler <nbowler@draconx.ca> - 2025-05-06 19:06 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-06 13:21 -0700
Re: Regarding assignment to struct Nick Bowler <nbowler@draconx.ca> - 2025-05-07 19:09 +0000
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-07 14:23 -0700
Re: Regarding assignment to struct Nick Bowler <nbowler@draconx.ca> - 2025-05-08 12:58 +0000
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-07 21:17 -0700
Re: Regarding assignment to struct Andrey Tarasevich <noone@noone.net> - 2025-05-29 05:36 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-29 14:36 -0700
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 07:56 -0700
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-05 20:00 +0200
Re: Regarding assignment to struct NotAorB <atod101101@gmail.com> - 2025-05-12 16:38 -0400
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-03 11:46 +0200
Re: Regarding assignment to struct Muttley@dastardlyhq.com - 2025-05-05 08:50 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-05 13:34 +0200
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-05 13:53 -0700
Re: Regarding assignment to struct Muttley@DastardlyHQ.org - 2025-05-06 07:16 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-06 11:46 +0200
Re: Regarding assignment to struct Muttley@DastardlyHQ.org - 2025-05-06 10:18 +0000
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-06 16:34 +0300
Re: Regarding assignment to struct Richard Damon <richard@damon-family.org> - 2025-05-03 21:42 -0400
Re: Regarding assignment to struct Michael S <already5chosen@yahoo.com> - 2025-05-04 11:01 +0300
Re: Regarding assignment to struct Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-05-04 08:34 +0000
Re: Regarding assignment to struct David Brown <david.brown@hesbynett.no> - 2025-05-04 14:06 +0200
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-05 21:25 -0700
Re: Regarding assignment to struct Rosario19 <Ros@invalid.invalid> - 2025-05-12 11:23 +0200
Re: Regarding assignment to struct Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-05-04 07:49 -0700
Re: Regarding assignment to struct Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-05-04 14:09 -0700
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Date | 2025-05-06 16:34 +0300 |
| Message-ID | <20250506163456.000053a1@yahoo.com> |
| In reply to | #393186 |
On Mon, 05 May 2025 13:53:10 -0700 Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote: > Muttley@dastardlyhq.com writes: > [...] > > If you twant o pass an actual array to a function instead of a > > pointer to it, embedding it in a structure is the only way to do > > it. > > Yes, but that's not necessarily useful. An array that's a member > of a struct can only be of a constant length (unless it's a flexible > array member, but that doesn't help). Functions that work with > arrays typically need to deal with arrays of arbitrary length. > It seems, C++ authorities were feeling that the pattern "struct with array of constant length as an only member" is very common. Otherwise they wouldn't bother to add <array> to their standard library.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <richard@damon-family.org> |
|---|---|
| Date | 2025-05-03 21:42 -0400 |
| Message-ID | <3fd0dce206153c0d2dc7cf26291165c3381e9bc2@i2pn2.org> |
| In reply to | #393106 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Michael S <already5chosen@yahoo.com> |
|---|---|
| Date | 2025-05-04 11:01 +0300 |
| Message-ID | <20250504110117.00005aaa@yahoo.com> |
| In reply to | #393126 |
On Sat, 3 May 2025 21:42:37 -0400 Richard Damon <richard@damon-family.org> wrote: > > Bigger than that, and you likely want to pass the object by address, > not by value, passing just a pointer to it. That sort of thinking is an example of Knutian premature optimization.
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2025-05-04 08:34 +0000 |
| Message-ID | <vv78q3$1isnh$1@dont-email.me> |
| In reply to | #393129 |
On Sun, 4 May 2025 11:01:17 +0300, Michael S wrote: > That sort of thinking is an example of Knutian premature optimization. Trying to hold back the optimization tide?
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2025-05-04 14:06 +0200 |
| Message-ID | <vv7l86$1t1h2$2@dont-email.me> |
| In reply to | #393130 |
On 04/05/2025 10:34, Lawrence D'Oliveiro wrote: > On Sun, 4 May 2025 11:01:17 +0300, Michael S wrote: > >> That sort of thinking is an example of Knutian premature optimization. > > Trying to hold back the optimization tide? I think he meant Knuthian, rather than Knutian :-)
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2025-05-05 21:25 -0700 |
| Message-ID | <86zffq2wnn.fsf@linuxsc.com> |
| In reply to | #393129 |
Michael S <already5chosen@yahoo.com> writes: > On Sat, 3 May 2025 21:42:37 -0400 > Richard Damon <richard@damon-family.org> wrote: > >> Bigger than that, and you likely want to pass the object by address, >> not by value, passing just a pointer to it. > > That sort of thinking is an example of Knutian premature optimization. I don't agree with this assessment. First, the given suggestion is a rule of thumb. By their nature rules of thumb offer heuristics that give guidelines likely to yield good results, but not guaranteed to do so. Second, a decision about whether to pass a struct object or a pointer to said object is often one that is a fair amount of work to undo, and so tends to be made early during the time period of program development. As such, it is useful to follow a guideline likely to give good results, even if not always optimal, because on average it will mean less work done overall. I second Richard Damon's recommendation, with the understanding that it is only a guideline, not an absolute, and as always subject to later revision should that turn out to be called for (no pun intended).
[toc] | [prev] | [next] | [standalone]
| From | Rosario19 <Ros@invalid.invalid> |
|---|---|
| Date | 2025-05-12 11:23 +0200 |
| Message-ID | <6bf32kdoevng89co5phme8p7ai4048ht60@4ax.com> |
| In reply to | #393129 |
On Sun, 4 May 2025 11:01:17 +0300, Michael S wrote: >On Sat, 3 May 2025 21:42:37 -0400 >Richard Damon <richard@damon-family.org> wrote: > >> >> Bigger than that, and you likely want to pass the object by address, >> not by value, passing just a pointer to it. > >That sort of thinking is an example of Knutian premature optimization. i prefer pass memory (if it is big enought) with one address or reference
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2025-05-04 07:49 -0700 |
| Message-ID | <868qnc77o4.fsf@linuxsc.com> |
| In reply to | #393106 |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> 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.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2025-05-04 14:09 -0700 |
| Message-ID | <8734dkozfg.fsf@nosuchdomain.example.com> |
| In reply to | #393106 |
Lew Pitcher <lew.pitcher@digitalfreehold.ca> 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?
Struct and union assignment (and argument passing, and returning from
functions) are fundamental features of the C language. You won't
find a C compiler that doesn't fully and correctly support them,
except perhaps ancient compilers from the 1980s or non-conforming
C-like compilers for tiny embedded systems.
There could be potential performance issues passing large structures,
but I wouldn't worry about that unless (a) the structures are
*very* large or (b) you have unusually tight resource constraints.
Someone in this thread suggested avoiding assignment for structs
bigger than twice the size of a pointer, but I'd set the cutoff
substantially higher than that.
For example, in one particular implementation a C++ std::string is
32 bytes and a std::vector is 24 bytes. C++ programmers routinely
pass these by value and copy them, and it doesn't cause any serious
problems. There shouldn't be a problem treating similarly sized
C structs by value. It Just Works.
Of course if you want to pass a structure to a function and have
the function modify it, you need to pass a pointer. You'd do the
same for a scalar parameter.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [standalone]
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
Back to top | Article view | comp.lang.c
csiph-web