蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年6月6日 10:18


请问!!!c 语言头文件问题

头文件<  stdrag>;中调用函数有va_strat,va_arg,va_end 这三个函数如何使用,请说细一点 :em06:

请问!!!c 语言头文件问题

man va_start

[code]

void OYCL_CSem::SetAll(int iSems, ...)
{
        if (iSems != m_iSems)
                return;//throw OYCL_CException("argument error.", __FILE__, __LINE__);
       
        unsigned short int* pusiValue = new unsigned short int [iSems];
       
        va_list ap;
        va_start(ap, iSems);
        for (int i = 0; i < iSems; i++)
                pusiValue[i] = (unsigned short int)va_arg(ap, int);
        va_end(ap);
       
        semun unSem;
        unSem.array = pusiValue;
        if (semctl(m_iSemId, 0, SETALL, unSem) < 0)
        {
                delete [] pusiValue;
                return;//throw OYCL_CException(strerror(errno), __FILE__, __LINE__);
        }
       
        delete [] pusiValue;
}[/code]

请问!!!c 语言头文件问题

va_arg()
[code]
#include <stdio.h>;
#include <stdarg.h>;
#include <stdlib.h>;
                                                                                                
static void test_fn( const char *msg,
                     const char *types,
                     ... );
                                                                                                
int main( void )
  {
    printf( "VA...TEST\n" );
    test_fn( "PARAMETERS: 1, \"abc\", 546",
         "isi", 1, "abc", 546 );
    test_fn( "PARAMETERS: \"def\", 789",
         "si", "def", 789 );
    return EXIT_SUCCESS;
  }
                                                                                                
static void test_fn(
  const char *msg,   /* message to be printed     */
  const char *types, /* parameter types (i,s)     */
  ... )          /* variable arguments     */
  {
    va_list argument;
    int   arg_int;
    char *arg_string;
    const char *types_ptr;
                                                                                                
    types_ptr = types;
    printf( "\n%s -- %s\n", msg, types );
    va_start( argument, types );
    while( *types_ptr != '\0' ) {
      if (*types_ptr == 'i') {
        arg_int = va_arg( argument, int );
        printf( "integer: %d\n", arg_int );
      } else if (*types_ptr == 's') {
        arg_string = va_arg( argument, char * );
        printf( "string:  %s\n", arg_string );
      }
      ++types_ptr;
    }
    va_end( argument );
  }
[/code]

va_end()
[code]
Synopsis:

#include <stdarg.h>;

void va_end( va_list param );

Library:

libc
Description:

The va_end() macro is used to complete the acquisition of
arguments from a list of variable arguments. It must be used
with the associated macros va_start() and va_arg(). See the description for va_arg() for complete documentation on these
macros.
[/code]

请问!!!c 语言头文件问题

楼上的高

请问!!!c 语言头文件问题

请问,运行结果是什么

请问!!!c 语言头文件问题



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com