在CVI中,是否支持一个有冲突变量的函数?
主要软件: LabWindows/CVI Development Systems>>LabWindows/CVI Full Development System
主要软件版本: 3.1
主要软件修正版本: N/A
次要软件: N/A
问题: 在CVI中,是否支持一个有冲突变量的函数?
解答: 是的,您可以在CVI的编写有冲突变量的函数。下面是一个从ANSI C书上选取的例子。ANSI C支持这点,所以CVI也支持。
#include <stdio.h>
#include <stdarg.h>
float average(int num, ...);
main()
{
float x;
x = average(10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
printf("\nThe first average is %f.", x);
x = average(5, 121, 206, 76, 31, 5);
printf("\nThe second average is %f.", x);
}
float average(int num, ...)
{
/* declare a variable of type va_list */
va_list arg_ptr;
int count;
int total=0;
/* initialize the argument pointer */
va_start(arg_ptr, num);
for (count=0; count < num; count++)
total += va_arg(arg_ptr, int);
/* clean up */
va_end(arg_ptr);
return((float)total/num);
}
相关链接:
附件:
报告日期: 11/15/2006
最近更新: 11/22/2006
文档编号: 0DR722ZL
Other Support Options
Ask the NI Community
Collaborate with other users in our discussion forums
Request Support from an Engineer
A valid service agreement may be required, and support options vary by country.