Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16600

Re: variadic function

From blp@cs.stanford.edu (Ben Pfaff)
Newsgroups comp.lang.c
Subject Re: variadic function
Date 2012-02-01 10:45 -0800
Message-ID <874nvamlyf.fsf@blp.benpfaff.org> (permalink)
References (3 earlier) <kfnty3k9rdd.fsf@x-alumni2.alumni.caltech.edu> <lnmx9c59x8.fsf@nuthaus.mib.org> <kfnwr87z40v.fsf@x-alumni2.alumni.caltech.edu> <ln39avw19d.fsf@nuthaus.mib.org> <jgc10d$av1$1@dont-email.me>

Show all headers | View raw


Shao Miller <sha0.miller@gmail.com> writes:

> On 2/1/2012 00:50, Keith Thompson wrote:
>>
>> Ok, that might be an interesting point.
>>
>> Do you suggest that there are *realistic* cases where a call to a
>> variadic function passes N arguments, and the function itself processes
>> fewer than N arguments, and where this does not indicate a logical error
>> in the program?
>>
>
> I don't know if the following might qualify (please forgive any minor
> errors):
>
>   int first_nonzero_value(int count, ...) {
>       va_list varargs;
>       int test;
>
>       va_start(varargs, count);
>       while (count--) {
>           test = va_arg(varargs, int);
>           if (test)
>             break;
>           continue;
>         }
>       va_end(varargs);
>       return test;
>     }

How about this:

int max(int count, ...) {
        int max = INT_MIN;
        va_list args;

        va_start(args, count);
        do {
                int value = va_arg(args, int);
                if (value > max)
                        max = value;
        } while (--count && max != INT_MAX);
        va_end(args);

        return max;
}
-- 
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

variadic function Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2011-11-05 22:32 +0000
  Re: variadic function Keith Thompson <kst-u@mib.org> - 2011-11-05 15:50 -0700
    Re: variadic function Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2011-11-07 17:41 +0000
  Re: variadic function James Kuyper <jameskuyper@verizon.net> - 2011-11-05 18:53 -0400
    Re: variadic function Keith Thompson <kst-u@mib.org> - 2011-11-05 16:35 -0700
      Re: variadic function Kaz Kylheku <kaz@kylheku.com> - 2011-11-06 01:36 +0000
  Re: variadic function Kaz Kylheku <kaz@kylheku.com> - 2011-11-06 01:31 +0000
  Re: variadic function Barry Schwarz <schwarzb@dqel.com> - 2011-11-06 09:45 -0800
    Re: variadic function Keith Thompson <kst-u@mib.org> - 2011-11-06 11:38 -0800
      Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-24 23:24 -0800
        Re: variadic function Keith Thompson <kst-u@mib.org> - 2012-01-25 02:54 -0800
          Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-31 18:22 -0800
            Re: variadic function Keith Thompson <kst-u@mib.org> - 2012-01-31 21:50 -0800
              Re: variadic function James Kuyper <jameskuyper@verizon.net> - 2012-02-01 07:55 -0500
              Re: variadic function Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-02-01 08:06 -0500
                Re: variadic function Keith Thompson <kst-u@mib.org> - 2012-02-01 11:42 -0800
              Re: variadic function Willem <willem@toad.stack.nl> - 2012-02-01 16:15 +0000
                Re: variadic function Keith Thompson <kst-u@mib.org> - 2012-02-01 11:41 -0800
              Re: variadic function Shao Miller <sha0.miller@gmail.com> - 2012-02-01 13:41 -0500
                Re: variadic function blp@cs.stanford.edu (Ben Pfaff) - 2012-02-01 10:45 -0800
              Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-08 10:30 -0800
                Re: variadic function Keith Thompson <kst-u@mib.org> - 2012-03-08 13:57 -0800
                Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-09 13:10 -0800
                Re: variadic function jgk@panix.com (Joe keane) - 2012-03-11 07:56 +0000
                Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-11 13:01 -0700
                Re: variadic function jgk@panix.com (Joe keane) - 2012-03-12 19:04 +0000
                Re: variadic function Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-13 15:05 -0700

csiph-web