Sujet : Re: That depends... (Was: Regarding assignment to struct)
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 05. May 2025, 19:47:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250505113452.570@kylheku.com>
References : 1 2 3 4 5 6 7
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-05-05, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
On 03.05.2025 07:11, Kaz Kylheku wrote:
Expanding on this point, C++ goes to town with pass-by-value interfaces
involving objects. For instance the std::basic_string template allows
C++ programs to treat dynamic strings as just values to be tossed
around:
std::string path_combine(std::string dir, std::string name)
{
return dir + "/" + name;
}
>
Hmm.. - my C++ days were long ago but I seem to recall that the
suggestion for passing non-trivial objects by-value was that they
should instead be passed by 'const &' (as a "quasi-by-value") for
performance reasons.
Right; but we don't have to.
I was going to add something else, and started exploring the
generated code for simple functions that just do a + b on
a pair of strings, and trivial functions which call them.
The code generated by GNU C++ with -O3 is so abhorrently verbose,
whether you use const references or go by-value, that I have no appetite
to go into it.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca