view test/tstdarg.c @ 492:cc1a5f764782

*** empty log message ***
author kono
date Wed, 21 Dec 2005 12:10:43 +0900
parents 0c256ea2a97e
children fe37f32b552b
line wrap: on
line source



#include <stdio.h>
#include <stdarg.h>

int
var_args(char *numtypes, ...)
{
    int t;
    int i;
    float f;
    double d;
    long long l;
    char *s;
    va_list ap;

    va_start(ap,numtypes);

    while((t= *numtypes++)) {
	if (t=='i') {
	    i = va_arg(ap,int);
	    printf("#0021:int arg: %d\n",i);
#if 0
	} else if (t=='f') {
	    f = va_arg(ap,float);
	    printf("#0025:float arg: %g\n",f);
#endif
	} else if (t=='d') {
	    d = va_arg(ap,double);
	    printf("#0029:double arg: %g\n",d);
	} else if (t=='l') {
	    l = va_arg(ap,long long);
	    printf("#0032:long long arg: %lld\n",l);
	} else if (t=='s') {
	    s = va_arg(ap,char *);
	    printf("#0035:char *arg: %s\n",s);
	} else {
	    s = va_arg(ap,char *);
	    printf("#0038:arg: error\n");
	}
    }
}


main()
{

    var_args("iiiiii",1,2,3,4,5,6);
    var_args("llllll",(long long)1,(long long)2,(long long)3,(long long)4,(long long)5,(long long)6);
#if 0
    var_args("ffffff",(float)1,(float)2,(float)3,(float)4,(float)5,(float)6);
#endif
    var_args("dddddd",(double)1,(double)2,(double)3,(double)4,(double)5,(double)6);
    var_args("ssssss","1","2","3","4","5","6");
    return 0; 
}