view test/tstdarg.c @ 285:912b54949344

register assop const ( int/long )
author kono
date Tue, 01 Jun 2004 12:42:36 +0900
parents
children 117baacd1ed0
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("int arg: %d\n",i);
	} else if (t=='f') {
#if 0
	    f = va_arg(ap,float);
#ele
	    f = va_arg(ap,double);
#endif
	    printf("float arg: %g\n",f);
	} else if (t=='d') {
	    d = va_arg(ap,double);
	    printf("double arg: %g\n",d);
	} else if (t=='l') {
	    l = va_arg(ap,long long);
	    printf("long long arg: %lld\n",l);
	} else if (t=='s') {
	    s = va_arg(ap,char *);
	    printf("char *arg: %s\n",s);
	} else {
	    s = va_arg(ap,char *);
	    printf("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);
    var_args("ffffff",(float)1,(float)2,(float)3,(float)4,(float)5,(float)6);
    var_args("dddddd",(double)1,(double)2,(double)3,(double)4,(double)5,(double)6);
    var_args("ssssss","1","2","3","4","5","6");
    
}