Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"A verbal contract isn't worth the paper it's printed on." -- Samuel Goldwyn


devel / comp.lang.c / Variadic functions

SubjectAuthor
* Variadic functionsMalcolm McLean
+- Re: Variadic functionsKaz Kylheku
+- Re: Variadic functionsKeith Thompson
+- Re: Variadic functionsLawrence D'Oliveiro
+- Re: Variadic functionsJames Kuyper
+* Re: Variadic functionsJanis Papanagnou
|`* Re: Variadic functionsMalcolm McLean
| +* Re: Variadic functionsSpiros Bousbouras
| |+* Re: Variadic functionsMalcolm McLean
| ||`- Re: Variadic functionsRichard Harnden
| |`* Re: Variadic functionsBlue-Maned_Hawk
| | `* Re: Variadic functionsLawrence D'Oliveiro
| |  +* Re: Variadic functionsMalcolm McLean
| |  |+- Re: Variadic functionsDavid Brown
| |  |`* Re: Variadic functionsScott Lurndal
| |  | +* Re: Variadic functionsLawrence D'Oliveiro
| |  | |`* Re: Variadic functionsDavid Brown
| |  | | +* Re: Variadic functionsJanis Papanagnou
| |  | | |`- Re: Variadic functionsDavid Brown
| |  | | +* Re: Variadic functionsLawrence D'Oliveiro
| |  | | |`* Re: Variadic functionsDavid Brown
| |  | | | `* Re: Variadic functionsLawrence D'Oliveiro
| |  | | |  `* Re: Variadic functionsKenny McCormack
| |  | | |   +- Re: Variadic functionsKaz Kylheku
| |  | | |   `- Re: Variadic functionsLawrence D'Oliveiro
| |  | | `* Re: Variadic functionsMalcolm McLean
| |  | |  +- Re: Variadic functionsKaz Kylheku
| |  | |  +- Re: Variadic functionsJames Kuyper
| |  | |  +- Re: Variadic functionsDavid Brown
| |  | |  `* Re: Variadic functionsKeith Thompson
| |  | |   `* Re: Variadic functionsMalcolm McLean
| |  | |    +* Re: Variadic functionsScott Lurndal
| |  | |    |+- Re: strings (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |    |`- Re: Variadic functionsDavid Brown
| |  | |    +* Re: Variadic functionsKaz Kylheku
| |  | |    |`- Re: Variadic functionsMalcolm McLean
| |  | |    `* Re: Variadic functionsDavid Brown
| |  | |     `* Re: Variadic functionsMalcolm McLean
| |  | |      `* Re: Variadic functionsDavid Brown
| |  | |       `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Chris M. Thomasson
| |  | |        +* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)bart
| |  | |        |`* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        | +* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)bart
| |  | |        | |`- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        | `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Tim Rentsch
| |  | |        |  `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        |   +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Kaz Kylheku
| |  | |        |   `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Kenny McCormack
| |  | |        |    +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Kaz Kylheku
| |  | |        |    `- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Kenny McCormack
| |  | |        +* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Keith Thompson
| |  | |        |`* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        | `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Keith Thompson
| |  | |        |  +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Lawrence D'Oliveiro
| |  | |        |  `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)jak
| |  | |        |   `- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)David Brown
| |  | |        +- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)David Brown
| |  | |        `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Malcolm McLean
| |  | |         `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Chris M. Thomasson
| |  | |          `* Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)David Brown
| |  | |           `- Re: Bad String Functions; Bad Bad Bad (was Re: Variadic functions)Chris M. Thomasson
| |  | `* Re: Variadic functionsBlue-Maned_Hawk
| |  |  `* Re: Variadic functionsLawrence D'Oliveiro
| |  |   `* Re: Variadic functionsDavid Brown
| |  |    +* Re: Variadic functionsKaz Kylheku
| |  |    |+- Re: Variadic functionsScott Lurndal
| |  |    |+* Re: Variadic functionsKeith Thompson
| |  |    ||`* Re: Variadic functionsDavid Brown
| |  |    || `- Re: Variadic functionsKeith Thompson
| |  |    |+- Re: Variadic functionsJames Kuyper
| |  |    |`* Re: Variadic functionsDavid Brown
| |  |    | `* Re: Variadic functionsKeith Thompson
| |  |    |  `- Re: Variadic functionsDavid Brown
| |  |    +* Re: Variadic functionsLawrence D'Oliveiro
| |  |    |`- Re: Variadic functionsDavid Brown
| |  |    `* Re: Variadic functionsBlue-Maned_Hawk
| |  |     `- Re: Variadic functionsDavid Brown
| |  `- Re: Variadic functionsBlue-Maned_Hawk
| +* Re: Variadic functionsLawrence D'Oliveiro
| |`* Re: Variadic functionsMalcolm McLean
| | +- Re: Variadic functionsLawrence D'Oliveiro
| | +* Re: Variadic functionsbart
| | |+* Re: Variadic functionsMalcolm McLean
| | ||`* Re: Variadic functionsDavid Brown
| | || `* Re: Variadic functionsMalcolm McLean
| | ||  `* Re: Variadic functionsDavid Brown
| | ||   `* Re: Variadic functionsMalcolm McLean
| | ||    +* Re: Variadic functionsDavid Brown
| | ||    |`* Re: Variadic functionsMalcolm McLean
| | ||    | `* Re: Variadic functionsDavid Brown
| | ||    |  `* Re: Variadic functionsMalcolm McLean
| | ||    |   `- Re: Variadic functionsDavid Brown
| | ||    `* Re: Variadic functionsKaz Kylheku
| | ||     `* Re: Variadic functionsMalcolm McLean
| | ||      `- Re: Variadic functionsKaz Kylheku
| | |`- Re: Variadic functionsBlue-Maned_Hawk
| | +- Re: Variadic functionsKeith Thompson
| | `* Re: Variadic functionsLawrence D'Oliveiro
| |  `- Re: Variadic functionsKaz Kylheku
| `* Re: Variadic functionsLawrence D'Oliveiro
+* Re: Variadic functionsTim Rentsch
+- Re: Variadic functionsBlue-Maned_Hawk
`- Re: Variadic functionsChris M. Thomasson

Pages:12345
Variadic functions

<uoed9m$387sh$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48954&group=comp.lang.c#48954

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Variadic functions
Date: Fri, 19 Jan 2024 17:59:18 +0000
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Jan 2024 17:59:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="00861fded2491171dcd2668fd986a126";
logging-data="3415953"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZhoaJxO1aLPMSnLWQighhOHGyLB5kOmM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zqFFPR30KJ0BS84DRv4w29GolqU=
Content-Language: en-GB
 by: Malcolm McLean - Fri, 19 Jan 2024 17:59 UTC

Who has actually used a variadic function for any purpose other than
implementing printf-style format strings?

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<20240119103544.751@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48958&group=comp.lang.c#48958

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Fri, 19 Jan 2024 18:42:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <20240119103544.751@kylheku.com>
References: <uoed9m$387sh$1@dont-email.me>
Injection-Date: Fri, 19 Jan 2024 18:42:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ad95ce9a64147988794afabbd8369e5e";
logging-data="3430228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183JChlj6ePNNaZuF3Cyil4xbmJN/tvgak="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:PkzqL7GjkS4Jxnryu2HWqcJhuzA=
 by: Kaz Kylheku - Fri, 19 Jan 2024 18:42 UTC

On 2024-01-19, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

1. The fellows that designed some of the exec family syscalls in Unix.

2. Catenation of multiple strings. This type of thing:

cat_str(target, s1, s2, s3, ..., (char *) 0);

3. Similarly, constructing a list of elements:

make_list(e1, e2, ..., NOTVAL);

4. Emulating a fixed, optional argument in certain situations.
Example of this is the open function in POSIX.

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);

The mode requirement is only required if the flags indicate
creation, and this is implemented as:

int open(const char *, int, ...);

I have done a very similar thing a handful of times.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Variadic functions

<87jzo5cfga.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48962&group=comp.lang.c#48962

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Fri, 19 Jan 2024 11:04:37 -0800
Organization: None to speak of
Lines: 13
Message-ID: <87jzo5cfga.fsf@nosuchdomain.example.com>
References: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="557d127e5a9de6fbe9a4acea8ddca985";
logging-data="3437698"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qxWwWNIh3e7HgqDGrN83Q"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:c5VTSISnhp1bi7MpEXCsi//MUHA=
sha1:7U89VnFYPofbiRZnRSsHqVbTikc=
 by: Keith Thompson - Fri, 19 Jan 2024 19:04 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

execl(), execlp(), and execle() (specified by POSIX) are variadic.

The open() system call is variadic, since its mode argument is optional.
So are fcntl() and ioctl().

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Variadic functions

<uoevot$3bf9q$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48980&group=comp.lang.c#48980

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Fri, 19 Jan 2024 23:14:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <uoevot$3bf9q$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 19 Jan 2024 23:14:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e15dac640a9167fb7bc10933baa543b0";
logging-data="3521850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wCheCSi4orWJER+C0DoqG"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:AHvMQCcBawmKW3COl4qwiApWbaA=
 by: Lawrence D'Oliv - Fri, 19 Jan 2024 23:14 UTC

On Fri, 19 Jan 2024 17:59:18 +0000, Malcolm McLean wrote:

> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

GEGL and BABL <https://gegl.org/> have lots of these. For example, from
/usr/include/gegl-0.4/gegl-apply.h:

/**
* gegl_apply_op:
* @buffer: the #GeglBuffer to apply onto
* @operation_name: name of the operation to apply
* @...: the settings for the operation. Zero or more key/value pairs,
* ended terminated with NULL.
*
* Apply the operation to buffer, overwritting the contents of buffer.
*
*/
void gegl_apply_op (GeglBuffer *buffer,
const gchar *operation_name,
...) G_GNUC_NULL_TERMINATED;

Re: Variadic functions

<uof0rk$3bgmf$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48981&group=comp.lang.c#48981

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuyper@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Fri, 19 Jan 2024 18:33:08 -0500
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uof0rk$3bgmf$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 19 Jan 2024 23:33:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9750321ea01ce7725fc7a516a8e12d46";
logging-data="3523279"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19b7qJQ+iNeT/T/tfFEWbqDimsDw9uX2iI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lWwtiziYET5m/EIY5I/KmRB2Uwg=
Content-Language: en-US
In-Reply-To: <uoed9m$387sh$1@dont-email.me>
 by: James Kuyper - Fri, 19 Jan 2024 23:33 UTC

On Fri, 19 Jan 2024 17:59:18 +0000, Malcolm McLean wrote:

> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

I've used the IMSL C library for several programs. Each function in that
library took a fair number of optional argument groups. Each group
started with an integer identifying which group it was. The types of the
arguments varied from one option group to another. The IMSL functions
had to use the option group ID to determine what types to pass to
va_arg() when retrieving the values of those arguments. A special
integer value was reserved to indicate that there were no more optional
arguments.

We had to deliver our code to many different users, some of whom had
licenses for the IMSL library, and others that didn't. I created a
pseudo-IMSL library, whose functions had the same name and interface as
the the actual IMSL library. The actual functions were a very limited
subset of the actual IMSL library, and had seriously constrained
functionality. For instance, we only needed cubic splines, so my
replacement for the IMSL spline routine treated requests for splines of
all other orders as errors. I wrote them based upon publicly available
algorithms and black-box testing to determine how the real IMSL
functions dealt with various error conditions and corner cases. I was
surprised to find that they failed to catch a number of error
conditions, but I wrote bug-compatible substitutes that failed in
exactly the same way. I never looked at the actual IMSL code. The
comments inside those functions clearly credited both IMSL and the
public sources I used for those algorithms.

I informed my superiors of what I was doing, and asked them to check
with the company's lawyers to find out whether I was violating any
intellectual property laws. They never got back to me. We delivered my
minimum IMSL clone library to those of our users who didn't have IMSL
licenses.

Re: Variadic functions

<uog6fs$3klco$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48987&group=comp.lang.c#48987

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 11:15:23 +0100
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uog6fs$3klco$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 10:15:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="328670c488e5f92939165dd00129fdd6";
logging-data="3823000"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OyFB6lQYOVt0t+tOmIi5E"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:eloFZNWesTWlYP3EeXXy97/AWSQ=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <uoed9m$387sh$1@dont-email.me>
 by: Janis Papanagnou - Sat, 20 Jan 2024 10:15 UTC

On 19.01.2024 18:59, Malcolm McLean wrote:
> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

In "own" projects only rarely. One was for debugging with nested macros
that finally lead to, yes, printf arguments. (That was decades ago, so
memories are faint about other applications.) Later in C++ I used other
code patterns for such purposes.

Janis

Re: Variadic functions

<uoga8t$3l6mu$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48988&group=comp.lang.c#48988

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 11:19:57 +0000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uoga8t$3l6mu$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 11:19:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="11760bd3b7aeccc193d8e59b055fcf05";
logging-data="3840734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QxGB/DrWmLOicr+fPHwg8sxdr1L+Af9k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FqqPFu9UtNMn/slX2VIlCqv5xm0=
In-Reply-To: <uog6fs$3klco$1@dont-email.me>
Content-Language: en-GB
 by: Malcolm McLean - Sat, 20 Jan 2024 11:19 UTC

On 20/01/2024 10:15, Janis Papanagnou wrote:
> On 19.01.2024 18:59, Malcolm McLean wrote:
>> Who has actually used a variadic function for any purpose other than
>> implementing printf-style format strings?
>
> In "own" projects only rarely. One was for debugging with nested macros
> that finally lead to, yes, printf arguments. (That was decades ago, so
> memories are faint about other applications.) Later in C++ I used other
> code patterns for such purposes.
>
> Janis
>
Yes. It seems there are a few libraries that also use variadic
arguments. I tend not to do that sort of programming and I'm not very
familar with them.
But no-one has yet come up with an occasion where they implemented a
variadic function by choice, for code which they controlled, except for
printf style formatting. Either a hobby project or work code for which
they had ownership.
The obvious candidates are functions like min() or max(), but because of
the way C implements variadic functions, these aren't suitable.
min(2,a,b)is unacceptable because too easily confused with min3(2.0, a, b).

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<Kdccf9Gr26AQrYzxL@bongo-ra.co>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48993&group=comp.lang.c#48993

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spibou@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 16:52:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <Kdccf9Gr26AQrYzxL@bongo-ra.co>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me> <uoga8t$3l6mu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 20 Jan 2024 16:52:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="03400f2503c3eaaff6a9af6839acac68";
logging-data="3948387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Oya3TR2tFDhj8P+8Y3DQj"
Cancel-Lock: sha1:PTXGodM94V3ddG8w3UGJpwPkpsQ=
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
In-Reply-To: <uoga8t$3l6mu$1@dont-email.me>
 by: Spiros Bousbouras - Sat, 20 Jan 2024 16:52 UTC

On Sat, 20 Jan 2024 11:19:57 +0000
Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> Yes. It seems there are a few libraries that also use variadic
> arguments. I tend not to do that sort of programming and I'm not very
> familar with them.
> But no-one has yet come up with an occasion where they implemented a
> variadic function by choice, for code which they controlled, except for
> printf style formatting. Either a hobby project or work code for which
> they had ownership.

I asked a similar question on this group many years ago. One example given
was a function for concatenating strings which would accept as arguments a
variable number of strings.

> The obvious candidates are functions like min() or max(), but because of
> the way C implements variadic functions, these aren't suitable.
> min(2,a,b)is unacceptable because too easily confused with min3(2.0, a, b).

Re: Variadic functions

<uogu42$3ogib$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48994&group=comp.lang.c#48994

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 16:58:42 +0000
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uogu42$3ogib$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <Kdccf9Gr26AQrYzxL@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 16:58:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="11760bd3b7aeccc193d8e59b055fcf05";
logging-data="3949131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uo5riUpbMrlRP0tTcWhqA7jc1b1WumWM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fiohGbJYQjqy+KiFTcKK1dL/puc=
Content-Language: en-GB
In-Reply-To: <Kdccf9Gr26AQrYzxL@bongo-ra.co>
 by: Malcolm McLean - Sat, 20 Jan 2024 16:58 UTC

On 20/01/2024 16:52, Spiros Bousbouras wrote:
> On Sat, 20 Jan 2024 11:19:57 +0000
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>> Yes. It seems there are a few libraries that also use variadic
>> arguments. I tend not to do that sort of programming and I'm not very
>> familar with them.
>> But no-one has yet come up with an occasion where they implemented a
>> variadic function by choice, for code which they controlled, except for
>> printf style formatting. Either a hobby project or work code for which
>> they had ownership.
>
> I asked a similar question on this group many years ago. One example given
> was a function for concatenating strings which would accept as arguments a
> variable number of strings.
>
I've sometimes written a "cat" function. But I always write it to take
two strings. However I don't do much text processing.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<uoh2s7$3pana$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48997&group=comp.lang.c#48997

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!nntp.comgw.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: richard.nospam@gmail.invalid (Richard Harnden)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 18:19:51 +0000
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <uoh2s7$3pana$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <Kdccf9Gr26AQrYzxL@bongo-ra.co>
<uogu42$3ogib$1@dont-email.me>
Reply-To: nospam.harnden@invalid.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 18:19:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cfbb661e7e6260ade705acddcc52f96a";
logging-data="3975914"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18I+ElObROZKPaKm3W+xiQqz2dfecU6M1A="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+sGPI0H2/DhO6GFnvheZCWg5Ww0=
In-Reply-To: <uogu42$3ogib$1@dont-email.me>
Content-Language: en-GB
 by: Richard Harnden - Sat, 20 Jan 2024 18:19 UTC

On 20/01/2024 16:58, Malcolm McLean wrote:
> On 20/01/2024 16:52, Spiros Bousbouras wrote:
>> On Sat, 20 Jan 2024 11:19:57 +0000
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>>> Yes. It seems there are a few libraries that also use variadic
>>> arguments. I tend not to do that sort of programming and I'm not very
>>> familar with them.
>>> But no-one has yet come up with an occasion where they implemented a
>>> variadic function by choice, for code which they controlled, except for
>>> printf style formatting. Either a hobby project or work code for which
>>> they had ownership.
>>
>> I asked a similar question on this group many years ago. One example
>> given
>> was a function for concatenating strings which would accept as
>> arguments a
>> variable number of strings.
>>
> I've sometimes written a "cat" function. But I always write it to take
> two strings. However I don't do much text processing.
>

Did you not see Kaz's reply? This was his 2nd example.

Re: Variadic functions

<uohef2$3r4em$6@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=48998&group=comp.lang.c#48998

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 21:37:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uohef2$3r4em$6@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 20 Jan 2024 21:37:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e15dac640a9167fb7bc10933baa543b0";
logging-data="4035030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CqslqOEFSkP68fa+VmD6K"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:39+i2Yw3aW1LjCx088L0Mvn4CpA=
 by: Lawrence D'Oliv - Sat, 20 Jan 2024 21:37 UTC

On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:

> But no-one has yet come up with an occasion where they implemented a
> variadic function by choice, for code which they controlled ...

But the people who created these libraries we mentioned certainly did.

Re: Variadic functions

<uohhvs$3rpaa$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49001&group=comp.lang.c#49001

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 22:37:48 +0000
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <uohhvs$3rpaa$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 22:37:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="11760bd3b7aeccc193d8e59b055fcf05";
logging-data="4056394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/njkgbXCYXUTXGwRuqLJLpH7z2zqo3UGI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:y5qNej0w+mVCrLNEOYzGEyaHuV4=
Content-Language: en-GB
In-Reply-To: <uohef2$3r4em$6@dont-email.me>
 by: Malcolm McLean - Sat, 20 Jan 2024 22:37 UTC

On 20/01/2024 21:37, Lawrence D'Oliveiro wrote:
> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>
>> But no-one has yet come up with an occasion where they implemented a
>> variadic function by choice, for code which they controlled ...
>
> But the people who created these libraries we mentioned certainly did.
>
I was wrong. As was pointed out eslewhere. Kaz gave some examples. But
his first was of usage.

Of course someone must have taken the decision that the call to evoke an
external process would take a variable list of arguments rather than a
single string. However In find that, of thousands of functions in my
code base, not a single one is variadic except a few interfaces to vsprintf.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<uohird$3rub4$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49002&group=comp.lang.c#49002

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 22:52:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uohird$3rub4$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 20 Jan 2024 22:52:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e15dac640a9167fb7bc10933baa543b0";
logging-data="4061540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AFuYY/Y/9y2Z6ykdtvBtx"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:7GK5Uii1ZmyktEnNxZyd5PsaLB0=
 by: Lawrence D'Oliv - Sat, 20 Jan 2024 22:52 UTC

On Sat, 20 Jan 2024 22:37:48 +0000, Malcolm McLean wrote:

> Of course someone must have taken the decision that the call to evoke an
> external process would take a variable list of arguments rather than a
> single string.

And it can play merry hell with typesafeness. Though I was able to come up
with typesafe Python wrappers, for example, around the variadic functions
in those libraries I mentioned earlier.

Re: Variadic functions

<uohjet$3s00n$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49003&group=comp.lang.c#49003

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 23:02:54 +0000
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <uohjet$3s00n$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 20 Jan 2024 23:02:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b26e4d8877358ca1ee8cdab6f46f03ff";
logging-data="4063255"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JtJjfa6kRiqBvOsYTqTvy7H0vN8T2KqQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:7KltmPQFbIlkJeNV2hsxpsMfD3I=
Content-Language: en-GB
In-Reply-To: <uohhvs$3rpaa$1@dont-email.me>
 by: bart - Sat, 20 Jan 2024 23:02 UTC

On 20/01/2024 22:37, Malcolm McLean wrote:
> On 20/01/2024 21:37, Lawrence D'Oliveiro wrote:
>> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>>
>>> But no-one has yet come up with an occasion where they implemented a
>>> variadic function by choice, for code which they controlled ...
>>
>> But the people who created these libraries we mentioned certainly did.
> >
> I was wrong. As was pointed out eslewhere. Kaz gave some examples. But
> his first was of usage.
>
> Of course someone must have taken the decision that the call to evoke an
> external process would take a variable list of arguments rather than a
> single string. However In find that, of thousands of functions in my
> code base, not a single one is variadic except a few interfaces to
> vsprintf.

Variadic functions were likely added to implement *printf functions,
since the language didn't want to make special provision just for those.

Then a number of people decided to make use of the feature, although
less often than you might expect.

But it is not a desirable feature for general use as it is not type-safe.

The other thing is, calling a variadic function is a lot easier than
writing the body of one. That will likely put many off.

I wouldn't be able to do it without looking up some examples.

Re: Variadic functions

<86msszil32.fsf@linuxsc.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49005&group=comp.lang.c#49005

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17687@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 16:30:57 -0800
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <86msszil32.fsf@linuxsc.com>
References: <uoed9m$387sh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="92215711b06d8c3aeb5738d6959250bf";
logging-data="4084254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PKvSpI+auQ5OHD2+mNsOqjTaAfWWPa4o="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:WubdNp0VQT+1tiOAhAB5QB/2RmI=
sha1:u3VSRdPWQ8d20TCEmaovQRptjoY=
 by: Tim Rentsch - Sun, 21 Jan 2024 00:30 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> Who has actually used a variadic function for any purpose other than
> implementing printf-style format strings?

May I inquire as to why you are motivated to ask the question?

Re: Variadic functions

<uoi0ea$3tmbi$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49008&group=comp.lang.c#49008

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 02:44:25 +0000
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <uoi0ea$3tmbi$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me> <uohjet$3s00n$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 02:44:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef74072e6e16bb027db5ff5cce429f7f";
logging-data="4118898"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NknltJrx5RrcyTLcjOG50o3PbHKnYEsY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:/oaPhc/LgOzpCTVxjguRvwgLbL8=
Content-Language: en-GB
In-Reply-To: <uohjet$3s00n$1@dont-email.me>
 by: Malcolm McLean - Sun, 21 Jan 2024 02:44 UTC

On 20/01/2024 23:02, bart wrote:
> On 20/01/2024 22:37, Malcolm McLean wrote:
>> On 20/01/2024 21:37, Lawrence D'Oliveiro wrote:
>>> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>>>
>>>> But no-one has yet come up with an occasion where they implemented a
>>>> variadic function by choice, for code which they controlled ...
>>>
>>> But the people who created these libraries we mentioned certainly did.
>>  >
>> I was wrong. As was pointed out eslewhere. Kaz gave some examples. But
>> his first was of usage.
>>
>> Of course someone must have taken the decision that the call to evoke
>> an external process would take a variable list of arguments rather
>> than a single string. However In find that, of thousands of functions
>> in my code base, not a single one is variadic except a few interfaces
>> to vsprintf.
>
>
> Variadic functions were likely added to implement *printf functions,
> since the language didn't want to make special provision just for those.
>
> Then a number of people decided to make use of the feature, although
> less often than you might expect.
>
> But it is not a desirable feature for general use as it is not type-safe.
>
> The other thing is, calling a variadic function is a lot easier than
> writing the body of one. That will likely put many off.
>
> I wouldn't be able to do it without looking up some examples.
>
I have occasionally passed the wrong type to printf. Usually a long
integer to %d. But I can't recall an occasion where the problem wasn't
quickly fixed. Xcode gives a warning for mismatched format string
parameters, but of course it can't do that for roll your own.
The other thing is passing a raw pointer to %p instead of casting to
void *. Technically this is an error, but %p is only really useful for
temporary debug code, so it's just pointless typing to out the cast in.

Variardic functions are implemented with macros and it's a bit hard to
work out what is going on. But it's not that hard. I don't think it's a
good reason for avoiding them. On the other hand, I implemented a C++
variable length template expansion to produce a "simple JSON" which is
in effect a varidaic function with type information. But whilst I
implemented it myself, I can't remember exactly how it is supposed to
work or what the syntax means.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<87r0ibbdxi.fsf@nosuchdomain.example.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49009&group=comp.lang.c#49009

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sat, 20 Jan 2024 18:47:21 -0800
Organization: None to speak of
Lines: 46
Message-ID: <87r0ibbdxi.fsf@nosuchdomain.example.com>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f32b183f6a3583cdacf819dd58b033c9";
logging-data="4146551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rMUhSqklOGPg9aeP7KS/l"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:rcmld1dzldcDcdDh6AbAIwxShx4=
sha1:jr0RfJ5NZDAJWq+qt5Oql82e9NY=
 by: Keith Thompson - Sun, 21 Jan 2024 02:47 UTC

Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> On 20/01/2024 21:37, Lawrence D'Oliveiro wrote:
>> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>>
>>> But no-one has yet come up with an occasion where they implemented a
>>> variadic function by choice, for code which they controlled ...
>> But the people who created these libraries we mentioned certainly
>> did.
>>
> I was wrong. As was pointed out eslewhere. Kaz gave some examples. But
> his first was of usage.

Perhaps because your original post asked about *using* variadic
functions, not implementing them.

> Of course someone must have taken the decision that the call to evoke
> an external process would take a variable list of arguments rather
> than a single string.

The standard system() function takes a single string. As for the
exec*() functions, they correspond to the standard definition of main(),
which takes a sequence of strings.

> However In find that, of thousands of functions
> in my code base, not a single one is variadic except a few interfaces
> to vsprintf.

That's not surprising. <stdarg.h> (and its predecessor <varargs.h>)
were designed to allow *printf, *scanf, and similar functions to be
implemented in more or less portable C. The mechanism is used for
things very similar to printf and scanf, for functions that take an
arbitrarily long sequence of arguments (typically string pointers), and
occasionally for things that might be implemented in other languages
with overloading or default arguments.

For example open() takes an optional third argument. In pre-ANSI C,
function declarations didn't specify parameters, and it just worked. In
many languages, defining an optional argument is straightforward. In
post-ANSI C, the only way to do it is to make open() variadic -- which
means a compiler isn't required to diagnose a call that passes a dozen
arguments.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Variadic functions

<uoi0tj$3tmbi$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49010&group=comp.lang.c#49010

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: malcolm.arthur.mclean@gmail.com (Malcolm McLean)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 02:52:34 +0000
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <uoi0tj$3tmbi$2@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <86msszil32.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 21 Jan 2024 02:52:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef74072e6e16bb027db5ff5cce429f7f";
logging-data="4118898"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PiKpuQJElOSLVRqiPP2T4O+DXGI7wxcI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FdnzJ4dKXoWl5WRKCTv1uCKotC4=
Content-Language: en-GB
In-Reply-To: <86msszil32.fsf@linuxsc.com>
 by: Malcolm McLean - Sun, 21 Jan 2024 02:52 UTC

On 21/01/2024 00:30, Tim Rentsch wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>
>> Who has actually used a variadic function for any purpose other than
>> implementing printf-style format strings?
>
> May I inquire as to why you are motivated to ask the question?
>
I had a break from the newsgroup due to the spam and Google groups
discontinuation. Eventually I decided to overcome my reservations about
putting junk on my employer's machine and installed a newsreader.

There weren't any very interesting threads in the first 500 headers, so
I decided to start one. It's pure chattiness and with no serious
purpose, but if you've anything to say on variadic functions then of
course you are more than welcome to join in.

--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Re: Variadic functions

<uoi9c1$2gjc$3@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49014&group=comp.lang.c#49014

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 05:16:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uoi9c1$2gjc$3@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 05:16:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="942a1f970482f2e4dbf1b31185d2ff4b";
logging-data="82540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pjL3LsSvoTiwgVbf+oUjx"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:Wr0hp23zCdhGtM1ndQb4Vc5VY+A=
 by: Lawrence D'Oliv - Sun, 21 Jan 2024 05:16 UTC

On Sat, 20 Jan 2024 22:37:48 +0000, Malcolm McLean wrote:

> Of course someone must have taken the decision that the call to evoke an
> external process would take a variable list of arguments rather than a
> single string. However In find that, of thousands of functions in my
> code base, not a single one is variadic except a few interfaces to
> vsprintf.

I have the urge to implement one, purely to provide a counterexample. As
an excuse, I will use it to demonstrate a technique for typesafely calling
such a function from Python code via ctypes.

Re: Variadic functions

<20240120220320.127@kylheku.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49016&group=comp.lang.c#49016

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 06:05:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20240120220320.127@kylheku.com>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me> <uoi9c1$2gjc$3@dont-email.me>
Injection-Date: Sun, 21 Jan 2024 06:05:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="33c09ed4842a7f81f4877f94e0219235";
logging-data="95081"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QwOJtLR++12jZE5MgWE0hFd0UL52BY4I="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:7Ype7dKBKEGOd4XA66jaxUuCROY=
 by: Kaz Kylheku - Sun, 21 Jan 2024 06:05 UTC

On 2024-01-21, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Sat, 20 Jan 2024 22:37:48 +0000, Malcolm McLean wrote:
>
>> Of course someone must have taken the decision that the call to evoke an
>> external process would take a variable list of arguments rather than a
>> single string. However In find that, of thousands of functions in my
>> code base, not a single one is variadic except a few interfaces to
>> vsprintf.
>
> I have the urge to implement one, purely to provide a counterexample. As
> an excuse, I will use it to demonstrate a technique for typesafely calling
> such a function from Python code via ctypes.

You're going to implement variadic functions in Malcom's code base,
just to create a counterexample?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Variadic functions

<uoii8s$3jao$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49017&group=comp.lang.c#49017

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 07:48:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uoii8s$3jao$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 07:48:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="942a1f970482f2e4dbf1b31185d2ff4b";
logging-data="118104"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MuiikDN/stFeSX78wEQAV"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:oobO4gvakP6Kmh4GJlUrtgQJ4wo=
 by: Lawrence D'Oliv - Sun, 21 Jan 2024 07:48 UTC

On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:

> But no-one has yet come up with an occasion where they implemented a
> variadic function by choice, for code which they controlled ...

OK, I have done one. Just a simple one, to demonstrate how to make
typesafe calls to it via a Python wrapper. It’s part of my “Python Topics
Notebooks” collection <https://gitlab.com/ldo/python_topics_notebooks/>.
The C code (stack_calc.[ch]) is a very basic RPN calculator, which takes a
varargs list of operators (integer) and operands (real), and returns the
final calculated result.

The notebook that makes use of it is called “ctypes Tip Extra -- Calling A
Variadic Function”.

Re: Variadic functions

<uoj641$6io9$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49024&group=comp.lang.c#49024

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 13:27:30 +0000
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uoj641$6io9$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uoii8s$3jao$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 13:27:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b26e4d8877358ca1ee8cdab6f46f03ff";
logging-data="215817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Z4BvkwQlolZ1detGruwkM88pUnEk6mQk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:NNzsW12nnLfKbsclB0z8oZLkusM=
Content-Language: en-GB
In-Reply-To: <uoii8s$3jao$1@dont-email.me>
 by: bart - Sun, 21 Jan 2024 13:27 UTC

On 21/01/2024 07:48, Lawrence D'Oliveiro wrote:
> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>
>> But no-one has yet come up with an occasion where they implemented a
>> variadic function by choice, for code which they controlled ...
>
> OK, I have done one. Just a simple one, to demonstrate how to make
> typesafe calls to it via a Python wrapper. It’s part of my “Python Topics
> Notebooks” collection <https://gitlab.com/ldo/python_topics_notebooks/>.
> The C code (stack_calc.[ch]) is a very basic RPN calculator, which takes a
> varargs list of operators (integer) and operands (real), and returns the
> final calculated result.
>
> The notebook that makes use of it is called “ctypes Tip Extra -- Calling A
> Variadic Function”.

"Calling such a variadic function from C itself can be tricky, because
there is very limited type checking that the C compiler can do on such
calls."

This is exactly the problem. In your example, you go through a
verification process before calling the function, which is called
indirectly.

That is, the user-code in Python doesn't directly call 'stack_calc'.
This means that there is no real need for the C function to be variadic.

It could take a single pointer to any arbitrary C data structure that
can represent your sample expression. Or maybe two pointers to parallel
arrays. Or ...

So it still leaves C variadic functions as a solution looking for a
problem, a solution which is hard to make type-safe.

Re: Variadic functions

<uojgfu$87o7$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49027&group=comp.lang.c#49027

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 17:24:30 +0100
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <uojgfu$87o7$1@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uohef2$3r4em$6@dont-email.me>
<uohhvs$3rpaa$1@dont-email.me> <uohjet$3s00n$1@dont-email.me>
<uoi0ea$3tmbi$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 16:24:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f4a8733e1a1cb103c0f1641cff483645";
logging-data="270087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z5QQ+vItpI3FhfKzWiatih/ZPc/Wzozg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WWTxnRhJ2ftFJr1Ka0LHZ3rf2D4=
In-Reply-To: <uoi0ea$3tmbi$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 21 Jan 2024 16:24 UTC

On 21/01/2024 03:44, Malcolm McLean wrote:
> On 20/01/2024 23:02, bart wrote:
>> On 20/01/2024 22:37, Malcolm McLean wrote:
>>> On 20/01/2024 21:37, Lawrence D'Oliveiro wrote:
>>>> On Sat, 20 Jan 2024 11:19:57 +0000, Malcolm McLean wrote:
>>>>
>>>>> But no-one has yet come up with an occasion where they implemented a
>>>>> variadic function by choice, for code which they controlled ...
>>>>
>>>> But the people who created these libraries we mentioned certainly did.
>>>  >
>>> I was wrong. As was pointed out eslewhere. Kaz gave some examples.
>>> But his first was of usage.
>>>
>>> Of course someone must have taken the decision that the call to evoke
>>> an external process would take a variable list of arguments rather
>>> than a single string. However In find that, of thousands of functions
>>> in my code base, not a single one is variadic except a few interfaces
>>> to vsprintf.
>>
>>
>> Variadic functions were likely added to implement *printf functions,
>> since the language didn't want to make special provision just for those.
>>
>> Then a number of people decided to make use of the feature, although
>> less often than you might expect.
>>
>> But it is not a desirable feature for general use as it is not type-safe.
>>
>> The other thing is, calling a variadic function is a lot easier than
>> writing the body of one. That will likely put many off.
>>
>> I wouldn't be able to do it without looking up some examples.
>>
> I have occasionally passed the wrong type to printf. Usually a long
> integer to %d. But I can't recall an occasion where the problem wasn't
> quickly fixed. Xcode gives a warning for mismatched format string
> parameters, but of course it can't do that for roll your own.

Of course you can.

XCode uses clang, IIUIC, and both gcc and clang have extensions
(attributes) for checking printf and scanf style strings and the
variadic parameters. They only work with compile-time known format
strings, understandably enough, but are fine for making your own checked
functions for logging, debug prints, or whatever.

That doesn't help for other types of variadic functions, however, and
you they are never as type-safe as functions with full non-variadic
prototypes.

> The other thing is passing a raw pointer to %p instead of casting to
> void *. Technically this is an error, but %p is only really useful for
> temporary debug code, so it's just pointless typing to out the cast in.
>
> Variardic functions are implemented with macros and it's a bit hard to
> work out what is going on. But it's not that hard. I don't think it's a
> good reason for avoiding them. On the other hand, I implemented a C++
> variable length template expansion to produce a "simple JSON" which is
> in effect a varidaic function with type information. But whilst I
> implemented it myself, I can't remember exactly how it is supposed to
> work or what the syntax means.
>

Variadic templates in C++ are typesafe, which is a big improvement over C.

Re: Variadic functions

<uok2cc$cgf7$3@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49039&group=comp.lang.c#49039

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 21:29:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uok2cc$cgf7$3@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uoii8s$3jao$1@dont-email.me>
<uoj641$6io9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 21 Jan 2024 21:29:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="942a1f970482f2e4dbf1b31185d2ff4b";
logging-data="410087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aFmnVY6spw9tz1BAkWemB"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:xWK42HMklHtrx3aOij7KFcP3kX8=
 by: Lawrence D'Oliv - Sun, 21 Jan 2024 21:29 UTC

On Sun, 21 Jan 2024 13:27:30 +0000, bart wrote:

> That is, the user-code in Python doesn't directly call 'stack_calc'.
> This means that there is no real need for the C function to be variadic.
>
> It could take a single pointer to any arbitrary C data structure that
> can represent your sample expression. Or maybe two pointers to parallel
> arrays. Or ...

.... and be just as type-unsafe as the variadic option.

Re: Variadic functions

<uok35h$ck24$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=49042&group=comp.lang.c#49042

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Variadic functions
Date: Sun, 21 Jan 2024 21:43:13 +0000
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uok35h$ck24$2@dont-email.me>
References: <uoed9m$387sh$1@dont-email.me> <uog6fs$3klco$1@dont-email.me>
<uoga8t$3l6mu$1@dont-email.me> <uoii8s$3jao$1@dont-email.me>
<uoj641$6io9$1@dont-email.me> <uok2cc$cgf7$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 21 Jan 2024 21:43:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b26e4d8877358ca1ee8cdab6f46f03ff";
logging-data="413764"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+wcSA7dp4EKB618H5De4grUePsL1i3pw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8Zi56rbZwAVfaYcbvmPBBl3837M=
Content-Language: en-GB
In-Reply-To: <uok2cc$cgf7$3@dont-email.me>
 by: bart - Sun, 21 Jan 2024 21:43 UTC

On 21/01/2024 21:29, Lawrence D'Oliveiro wrote:
> On Sun, 21 Jan 2024 13:27:30 +0000, bart wrote:
>
>> That is, the user-code in Python doesn't directly call 'stack_calc'.
>> This means that there is no real need for the C function to be variadic.
>>
>> It could take a single pointer to any arbitrary C data structure that
>> can represent your sample expression. Or maybe two pointers to parallel
>> arrays. Or ...
>
> ... and be just as type-unsafe as the variadic option.

No, it wouldn't.

If you have that single pointer as type T*, then you can't for example
pass, when called from C, an int, or float, or U* pointer, or struct, as
happens with variadic.

Pages:12345
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor