Mercurial > hg > CbC > old > device
annotate test/tstdarg.c @ 896:d712ee10feb7
local_nptr for locally defined struct
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Apr 2014 19:20:58 +0900 |
parents | 5313ed059cee |
children |
rev | line source |
---|---|
285 | 1 |
2 | |
3 #include <stdio.h> | |
4 #include <stdarg.h> | |
5 | |
811
4c13e6784414
i64 stdarg (is this correct?)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
6 #if 0 |
809 | 7 void |
8 print(__builtin_va_list *ap) | |
9 { | |
10 #if 0 | |
11 printf( | |
12 " long long_last %0lx; \n" | |
13 " long float_first %0lx; \n" | |
14 " long float_last %0lx; \n" | |
15 " long stack_top %0lx; \n" | |
16 " long arg %0lx; \n" | |
17 " long top %0lx; \n", | |
18 ap->long_last , | |
19 ap->float_first , | |
20 ap->float_last , | |
21 ap->stack_top , | |
22 ap->arg , | |
23 ap->top ); | |
24 #endif | |
25 } | |
811
4c13e6784414
i64 stdarg (is this correct?)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
26 #else |
4c13e6784414
i64 stdarg (is this correct?)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
27 #define print(d) |
4c13e6784414
i64 stdarg (is this correct?)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
809
diff
changeset
|
28 #endif |
809 | 29 |
575 | 30 void |
285 | 31 var_args(char *numtypes, ...) |
32 { | |
33 int t; | |
34 int i; | |
35 float f; | |
36 double d; | |
37 long long l; | |
38 char *s; | |
39 va_list ap; | |
40 | |
41 va_start(ap,numtypes); | |
809 | 42 print(&ap); |
285 | 43 while((t= *numtypes++)) { |
880 | 44 if (t=='i') { |
45 i = va_arg(ap,int); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
46 printf("#0045:int arg: %d\n",i); |
809 | 47 print(&ap); |
794
032dc03be02e
i64 arg_register in inline mode
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
741
diff
changeset
|
48 |
741 | 49 #if 0 /* ‘float’ is promoted to ‘double’ when passed through ‘...’ */ |
880 | 50 } else if (t=='f') { |
51 f = va_arg(ap,float); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
52 printf("#0051:float arg: %g\n",f); |
285 | 53 #endif |
880 | 54 } else if (t=='d') { |
55 d = va_arg(ap,double); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
56 printf("#0055:double arg: %g\n",d); |
809 | 57 print(&ap); |
880 | 58 } else if (t=='l') { |
59 l = va_arg(ap,long long); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
60 printf("#0059:long long arg: %lld\n",l); |
809 | 61 print(&ap); |
880 | 62 } else if (t=='s') { |
63 s = va_arg(ap,char *); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
64 printf("#0063:char *arg: %s\n",s); |
809 | 65 print(&ap); |
880 | 66 } else { |
67 s = va_arg(ap,char *); | |
896
d712ee10feb7
local_nptr for locally defined struct
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
880
diff
changeset
|
68 printf("#0067:arg: error\n"); |
809 | 69 print(&ap); |
880 | 70 } |
285 | 71 } |
72 } | |
73 | |
540 | 74 int |
285 | 75 main() |
76 { | |
77 | |
78 var_args("iiiiii",1,2,3,4,5,6); | |
79 var_args("llllll",(long long)1,(long long)2,(long long)3,(long long)4,(long long)5,(long long)6); | |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
285
diff
changeset
|
80 #if 0 |
285 | 81 var_args("ffffff",(float)1,(float)2,(float)3,(float)4,(float)5,(float)6); |
305
117baacd1ed0
stdarg powerpc passed except long long (macro problem)
kono
parents:
285
diff
changeset
|
82 #endif |
285 | 83 var_args("dddddd",(double)1,(double)2,(double)3,(double)4,(double)5,(double)6); |
84 var_args("ssssss","1","2","3","4","5","6"); | |
306 | 85 return 0; |
285 | 86 } |