Mercurial > hg > CbC > old > device
view test/tstdarg.c @ 874:3454953b3df0
fix inline strinit not yet worked.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 01 Apr 2014 23:25:05 +0900 |
parents | 4c13e6784414 |
children | 5313ed059cee |
line wrap: on
line source
#include <stdio.h> #include <stdarg.h> #if 0 void print(__builtin_va_list *ap) { #if 0 printf( " long long_last %0lx; \n" " long float_first %0lx; \n" " long float_last %0lx; \n" " long stack_top %0lx; \n" " long arg %0lx; \n" " long top %0lx; \n", ap->long_last , ap->float_first , ap->float_last , ap->stack_top , ap->arg , ap->top ); #endif } #else #define print(d) #endif void var_args(char *numtypes, ...) { int t; int i; float f; double d; long long l; char *s; va_list ap; va_start(ap,numtypes); print(&ap); while((t= *numtypes++)) { if (t=='i') { i = va_arg(ap,int); printf("#0020:int arg: %d\n",i); print(&ap); #if 0 /* ‘float’ is promoted to ‘double’ when passed through ‘...’ */ } 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); print(&ap); } else if (t=='l') { l = va_arg(ap,long long); printf("#0032:long long arg: %lld\n",l); print(&ap); } else if (t=='s') { s = va_arg(ap,char *); printf("#0035:char *arg: %s\n",s); print(&ap); } else { s = va_arg(ap,char *); printf("#0038:arg: error\n"); print(&ap); } } } int 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; }