Article View: comp.lang.c
Article #742Re: variadic min and max, (any some and none, cat and more)
From: fir
Date: Sat, 24 Oct 2026 16:37
Date: Sat, 24 Oct 2026 16:37
114 lines
4875 bytes
4875 bytes
fir pisze:
> David Brown pisze:
>> On 23/10/2026 16:29, bartc wrote:
>>> On 23/10/2026 14:18, David Brown wrote:
>>>> On 23/10/2026 14:53, bartc wrote:
>>>
>>>>> OK. I'm don't know how to do solutions with macros. It is a harder
>>>>> language than C.
>>
>> Complex macros can be hairy. When they are used for things
>> significantly more advanced than envisioned when the C pre-processor
>> was conceived, and you don't often work with such macros, the results
>> can be hard to write and hard to understand. But they can still be
>> useful, and they can still be fun!
>>
>>>>
>>>> (I hope that in the future, you remember that I called your
>>>> solution, albeit with a macro for a slightly nicer interface, "not
>>>> bad". And remember also that I am Scottish - "not bad" is as
>>>> complimentary as we get!)
>>>
>>> I had to read it again. I assumed you were talking only about your
>>> version not mine!
>>
>> It was your list version. I improved it by using a macro so that the
>> calling syntax was nicer and the sentinel was not needed.
>>
>> None of this - your code or mine - is revolutionary or innovative, and
>> there are endless examples of similar code online. But I preferred
>> your use of a list to fir's use of va_args, with the compound
>> initialiser being the key to usability.
>>
>>
> im not quite understand what you say here (wak english) but theis
> "shallow varargs" with N passed via register could be quite usable
>
>
> like for min max for example
>
>
> min(a,b,c,d,e)
> you just write a function min bodli like for min(int*t)
> but you just have nice interface for all that tiny cases where you searh
> min in short cases like 2,3,4,5,6,7,8,6 arguments
>
> in comparsion to predefined versions for 2/3 arguments it would be a bit
> slower maybe but not so much,
> overally i find it rather usefull
>
those some any and none could also be implemented
like
int some (int a, ...)
{
for(int i=0; i<N; i++)
{
if(arg[i]) return 1;
}
return 0;
}
its good and logical..clasic c version (from ai)
ai says that you need to pass the N number explicitely and that sucks
i also dont know as to efficiency
#include <stdarg.h>
int some(int N,...)
{
int i;
int a;
va_list arg;
va_start(arg,N);
for(i=0;i<N;i++)
{
a=va_arg(arg,int);
if(a)
{
va_end(arg);
return 1;
}
}
va_end(arg);
return 0;
}
this efficienct of callsic varargs its said depends on architecture and
im not sure if i want to go into that (But if some has nothing to do may
found how it is and post on it ..i could see)
overally efficiency of thsi shouldnt be bad.. takin away the question
floding things on stack is overally slow, but if som e care it may
inline it and in this case probably this can be optimised
ant to get back to begining of this topic imo such one type varargs
could be quite usefull imo
thou its own form suggast thet the best implementation is
some(int* s)
it would allow pasing some(a,b,c,d,e) and some(tab) or maybe even
some(int3) (where int3 is a structure of 3 ints and using one code to it all
Technical Details
Message-ID:
<11bimsj$2sit1$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <11bfdcs$1mvrv$1@dont-email.me> <11bfhl3$1ojh8$1@dont-email.me> <11bflcp$1q9v8$1@dont-email.me> <11bfmqq$1ojh8$3@dont-email.me> <11bfr0q$1sivj$1@dont-email.me> <11bfs35$1ojh8$4@dont-email.me> <11bibgc$2nvgl$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: variadic min and max, (any some and none, cat and more) Date: Sat, 24 Oct 2026 18:37:38 +0200 Organization: A noiseless patient Spider Lines: 114 Message-ID: <11bimsj$2sit1$1@dont-email.me> References: <11bes8b$1gncr$1@dont-email.me> <11bf84v$1jkb5$1@dont-email.me> <11bfdcs$1mvrv$1@dont-email.me> <11bfhl3$1ojh8$1@dont-email.me> <11bflcp$1q9v8$1@dont-email.me> <11bfmqq$1ojh8$3@dont-email.me> <11bfr0q$1sivj$1@dont-email.me> <11bfs35$1ojh8$4@dont-email.me> <11bibgc$2nvgl$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 24 Oct 2026 16:37:40 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3034017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NW11RNSu32Eas7iPZzryS1l78V5gCNlk="; posting-host="b285b74d6a7e1db326de4fb86ea26fbc" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:PZZQ5V901kUAh3Db99d/mrEjPjA= sha256:D50Y0AonjjSBdC0f2FkKb2x2pn02jBT0DxNE/5asliA= sha1:fHmX58jJNaMQdY9yltMcDx/UoeU= sha256:/G5QR7RiUeQ3FvezdstLjZKeZ02fRnBXUIenUIIjWF4= In-Reply-To: <11bibgc$2nvgl$1@dont-email.me>