On 23/10/2026 06:44, fir wrote:
when thinkong on variadic functions not much come to mind but
only recently i noticed min or max would be good for variadic
the ai wrote me such variadic min
I don't think that I'd bother with stdarg at all.
Just use a string of ints ...
int min(const int *n)
{
int m = INT_MAX;
while ( *n )
{
if ( *n < m ) m = *n;
n++;
}
return m;
}
int a=Min(4,10,3,7,-2); // -2
int a = min((int[]){10,3,7,-2}));
On Sun, 25 Oct 2026 04:24:26 +0000, Richard Harnden wrote:
On 23/10/2026 06:44, fir wrote:
when thinkong on variadic functions not much come to mind but
only recently i noticed min or max would be good for variadic
the ai wrote me such variadic min
I don't think that I'd bother with stdarg at all.
Just use a string of ints ...
int min(const int *n)
{
int m = INT_MAX;
while ( *n )
{
if ( *n < m ) m = *n;
n++;
}
return m;
}
int a=Min(4,10,3,7,-2); // -2
int a = min((int[]){10,3,7,-2}));
in this way can not be used 0, in the 0 terminated list of integers...
I think would be better opertate in the INT_MAX terminate list of
integers (so the range would be INT_MIN..(INT_MAX-1)):
int min(int *n)
{int m=INT_MAX;
while ( *n!=INT_MAX )
{if ( *n < m ) m = *n;
n++;
}
return m;
}
this would be better because allow to use 0 too at cost to not use the INT_MAX value
I think would be better opertate in the INT_MAX terminate list of
integers (so the range would be INT_MIN..(INT_MAX-1)):
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 56:58:58 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
4 files (9,632K bytes) |
| Messages: | 285,828 |