Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      va_start

      From cppreference.com
      <cpp‎ |utility‎ |variadic
       
       
      Utilities library
       
       
      Defined in header<cstdarg>
      void va_start( std::va_list ap, parm_n);

      Theva_start macro enables access to the variable arguments following the named argumentparm_n.

      va_start should be invoked with an instance to a validva_list objectap before any calls tova_arg.

      If theparm_n is apack expansion or an entity resulting from alambda capture, the program is ill-formed, no diagnostic required.

      (since C++11)

      Ifparm_n is of reference type, or of a type not compatible with the type that results fromdefault argument promotions, the behavior is undefined.

      Contents

      [edit]Parameters

      ap - an object of theva_list type
      parm_n - the named parameter preceding the first variable parameter

      [edit]Expanded value

      (none)

      [edit]Notes

      va_start is required to supportparm_n with overloadedoperator&.

      [edit]Example

      Run this code
      #include <cstdarg>#include <iostream> int add_nums(int count...){int result=0;    std::va_list args;    va_start(args, count);for(int i=0; i< count;++i)        result+=va_arg(args,int);va_end(args);return result;} int main(){std::cout<< add_nums(4,25,25,50,50)<<'\n';}

      Output:

      150

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      CWG 273C++98it was unclear whetherva_start is required to
      supportparm_ns with overloadedoperator&
      required
      LWG 2099C++98the behavior was undefined ifparm_n is
      declared with a function, array, or reference type
      the behavior is undefined if
      parm_n is of reference type

      [edit]See also

      accesses the next variadic function argument
      (function macro)[edit]
      ends traversal of the variadic function arguments
      (function macro)[edit]
      C documentation forva_start
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/variadic/va_start&oldid=169935"

      [8]ページ先頭

      ©2009-2025 Movatter.jp