2 * TCC auto test program
5 /* Unfortunately, gcc version < 3 does not handle that! */
8 /* only gcc 3 handles _Bool correctly */
13 /* test various include syntaxes */
15 #define TCCLIB_INC <tcclib.h>
16 #define TCCLIB_INC1 <tcclib
17 #define TCCLIB_INC2 h>
18 #define TCCLIB_INC3 "tcclib"
22 #include TCCLIB_INC1.TCCLIB_INC2
24 #include TCCLIB_INC1.h>
26 #include TCCLIB_INC3 ".h"
48 void constant_expr_test();
50 void char_short_test();
52 void compound_literal_test(void);
54 void struct_assign_test(void);
56 void bitfield_test(void);
57 void c99_bool_test(void);
58 void float_test(void);
59 void longlong_test(void);
60 void stdarg_test(void);
61 void whitespace_test(void);
62 void relocation_test(void);
63 void old_style_function(void);
64 void sizeof_test(void);
65 void typeof_test(void);
69 void forward_ref(void);
75 #define M1(a, b) (a) + (b)
79 #define glue(a, b) a ## b
80 #define xglue(a, b) glue(a, b)
81 #define HIGHLOW "hello"
82 #define LOW LOW ", world"
84 #define min(a, b) ((a) < (b) ? (a) : (b))
87 #define dprintf(level,...) printf(__VA_ARGS__)
90 /* gcc vararg macros */
91 #define dprintf1(level, fmt, args...) printf(fmt, ## args)
93 #define MACRO_NOARGS()
109 #define __INT64_C(c) c ## LL
110 #define INT64_MIN (-__INT64_C(9223372036854775807)-1)
112 void macro_test(void)
114 printf("macro:\n");\f\v
116 printf("aaa=%d\n", AAA
);
118 printf("min=%d\n", min(1, min(2, -1)));
120 printf("s1=%s\n", glue(HIGH
, LOW
));
121 printf("s2=%s\n", xglue(HIGH
, LOW
));
122 printf("s3=%s\n", str("c"));
123 printf("s4=%s\n", str(a1
));
124 printf("B3=%d\n", B3
);
127 printf("A defined\n");
130 printf("B defined\n");
133 printf("A defined\n");
135 printf("A not defined\n");
138 printf("B defined\n");
140 printf("B not defined\n");
144 printf("A defined\n");
146 printf("B1 defined\n");
148 printf("B1 not defined\n");
151 printf("A not defined\n");
153 printf("B2 defined\n");
155 printf("B2 not defined\n");
160 printf("test true1\n");
163 printf("test true2\n");
166 printf("test true3\n");
169 printf("test trueA\n");
172 printf("test trueB\n");
188 printf("__LINE__ defined\n");
191 printf("__LINE__=%d __FILE__=%s\n",
194 printf("__LINE__=%d __FILE__=%s\n",
197 printf("__LINE__=%d __FILE__=%s\n",
199 #line 200 "tcctest.c"
201 /* not strictly preprocessor, but we test it there */
203 printf("__func__ = %s\n", __func__
);
204 dprintf(1, "vaarg=%d\n", 1);
206 dprintf1(1, "vaarg1\n");
207 dprintf1(1, "vaarg1=%d\n", 2);
208 dprintf1(1, "vaarg1=%d %d\n", 1, 2);
211 printf("func='%s'\n", __FUNCTION__
);
213 /* complicated macros in glibc */
214 printf("INT64_MIN=%Ld\n", INT64_MIN
);
224 /* comment with stray handling *\
258 printf("\141\1423\143\n");/* dezdez test */
259 printf("\x41\x42\x43\x3a\n");
260 printf("c=%c\n", 'r');
261 printf("wc=%C 0x%lx %C\n", L
'a', L
'\x1234', L
'c');
263 printf("wstring=%S\n", L
"abc");
264 printf("wstring=%S\n", L
"abc" L
"def" "ghi");
265 printf("'\\377'=%d '\\xff'=%d\n", '\377', '\xff');
266 printf("L'\\377'=%d L'\\xff'=%d\n", L
'\377', L
'\xff');
270 while ((b
= b
+ 1) < 96) {
274 printf("fib=%d\n", fib(33));
276 while (b
!= 0x80000000) {
289 for(i
= 0; i
< 10;i
++)
298 /* break/continue tests */
310 /* break/continue tests */
322 for(i
= 0;i
< 10;i
++) {
334 static void *label_table
[3] = { &&label1
, &&label2
, &&label3
};
347 /* we also test computed gotos (GCC extension) */
349 goto *label_table
[i
];
377 printf("enum:\n%d %d %d %d %d %d\n",
378 E0
, E1
, E2
, E3
, E4
, E5
);
380 printf("b1=%d\n", b1
);
391 printf("typedef:\n");
392 printf("a=%d\n", *a
);
397 printf("forward:\n");
403 void forward_ref(void)
405 printf("forward ok\n");
408 typedef struct struct1
{
428 struct struct1 st1
, st2
;
430 int main(int argc
, char **argv
)
448 constant_expr_test();
452 compound_literal_test();
454 struct_assign_test();
463 old_style_function();
476 printf("g1=%d\n", g
);
484 printf("g2=%d\n", g
);
488 printf("g3=%d\n", g
);
492 printf("g4=%d\n", g
);
495 printf("g5=%d\n", g
);
498 void array_test(int a
[4])
503 printf("sizeof(a) = %d\n", sizeof(a
));
504 printf("sizeof(\"a\") = %d\n", sizeof("a"));
506 printf("sizeof(__func__) = %d\n", sizeof(__func__
));
508 printf("sizeof tab %d\n", sizeof(tab
));
509 printf("sizeof tab2 %d\n", sizeof tab2
);
513 printf("%d %d %d\n", tab
[0], tab
[1], tab
[2]);
516 tab2
[i
][j
] = 10 * i
+ j
;
518 printf(" %3d", ((int *)tab2
)[i
]);
527 printf("%d\n", a
+= 1);
528 printf("%d\n", a
-= 2);
529 printf("%d\n", a
*= 31232132);
530 printf("%d\n", a
/= 4);
531 printf("%d\n", a
%= 20);
532 printf("%d\n", a
&= 6);
533 printf("%d\n", a
^= 7);
534 printf("%d\n", a
|= 8);
535 printf("%d\n", a
>>= 3);
536 printf("%d\n", a
<<= 4);
540 printf("%d\n", a
+ 1);
541 printf("%d\n", a
- 2);
542 printf("%d\n", a
* 312);
543 printf("%d\n", a
/ 4);
544 printf("%d\n", b
/ 4);
545 printf("%d\n", (unsigned)b
/ 4);
546 printf("%d\n", a
% 20);
547 printf("%d\n", b
% 20);
548 printf("%d\n", (unsigned)b
% 20);
549 printf("%d\n", a
& 6);
550 printf("%d\n", a
^ 7);
551 printf("%d\n", a
| 8);
552 printf("%d\n", a
>> 3);
553 printf("%d\n", b
>> 3);
554 printf("%d\n", (unsigned)b
>> 3);
555 printf("%d\n", a
<< 4);
560 printf("%d\n", 12 + 1);
561 printf("%d\n", 12 - 2);
562 printf("%d\n", 12 * 312);
563 printf("%d\n", 12 / 4);
564 printf("%d\n", 12 % 20);
565 printf("%d\n", 12 & 6);
566 printf("%d\n", 12 ^ 7);
567 printf("%d\n", 12 | 8);
568 printf("%d\n", 12 >> 2);
569 printf("%d\n", 12 << 4);
573 printf("%d %d %d %d\n",
582 return (c
>= 'a' & c
<= 'z') | (c
>= 'A' & c
<= 'Z') | c
== '_';
585 /**********************/
587 int vstack
[10], *vstack_ptr
;
589 void vpush(int vt
, int vc
)
595 void vpop(int *ft
, int *fc
)
608 vstack_ptr
[-2] &= ~0xffffff80;
610 printf("res= %d %d\n", a
, b
);
613 void constant_expr_test()
616 printf("constant_expr:\n");
618 printf("%d\n", a
* 16);
619 printf("%d\n", a
* 1);
620 printf("%d\n", a
+ 0);
629 printf("expr_ptr:\n");
632 printf("diff=%d\n", q
- p
);
634 printf("inc=%d\n", p
- tab4
);
636 printf("dec=%d\n", p
- tab4
);
638 printf("inc=%d\n", p
- tab4
);
640 printf("dec=%d\n", p
- tab4
);
641 printf("add=%d\n", p
+ 3 - tab4
);
642 printf("add=%d\n", 3 + p
- tab4
);
648 printf("constant_expr:\n");
651 printf("%d\n", a
== a
);
652 printf("%d\n", a
!= a
);
654 printf("%d\n", a
< b
);
655 printf("%d\n", a
<= b
);
656 printf("%d\n", a
<= a
);
657 printf("%d\n", b
>= a
);
658 printf("%d\n", a
>= a
);
659 printf("%d\n", b
> a
);
661 printf("%d\n", (unsigned)a
< b
);
662 printf("%d\n", (unsigned)a
<= b
);
663 printf("%d\n", (unsigned)a
<= a
);
664 printf("%d\n", (unsigned)b
>= a
);
665 printf("%d\n", (unsigned)a
>= a
);
666 printf("%d\n", (unsigned)b
> a
);
695 printf("sizes: %d %d %d %d\n",
696 sizeof(struct struct1
),
697 sizeof(struct struct2
),
698 sizeof(union union1
),
699 sizeof(union union2
));
703 printf("st1: %d %d %d\n",
704 st1
.f1
, st1
.f2
, st1
.f3
);
707 printf("union1: %d\n", st1
.u
.v1
);
710 printf("union2: %d\n", u
.w1
);
715 printf("st2: %d %d %d\n",
716 s
->f1
, s
->f2
, s
->f3
);
717 printf("str_addr=%x\n", (int)st1
.str
- (int)&st1
.f1
);
719 /* align / size tests */
720 printf("aligntest1 sizeof=%d alignof=%d\n",
721 sizeof(struct aligntest1
), __alignof__(struct aligntest1
));
722 printf("aligntest2 sizeof=%d alignof=%d\n",
723 sizeof(struct aligntest2
), __alignof__(struct aligntest2
));
724 printf("aligntest3 sizeof=%d alignof=%d\n",
725 sizeof(struct aligntest3
), __alignof__(struct aligntest3
));
726 printf("aligntest4 sizeof=%d alignof=%d\n",
727 sizeof(struct aligntest4
), __alignof__(struct aligntest4
));
729 /* empty structures (GCC extension) */
730 printf("sizeof(struct empty) = %d\n", sizeof(struct empty
));
731 printf("alignof(struct empty) = %d\n", __alignof__(struct empty
));
734 /* XXX: depend on endianness */
735 void char_short_test()
739 printf("char_short:\n");
744 *(char *)&var1
, *(char *)&var2
);
746 *(unsigned char *)&var1
, *(unsigned char *)&var2
);
747 printf("s16=%d %d\n",
748 *(short *)&var1
, *(short *)&var2
);
749 printf("u16=%d %d\n",
750 *(unsigned short *)&var1
, *(unsigned short *)&var2
);
751 printf("s32=%d %d\n",
752 *(int *)&var1
, *(int *)&var2
);
753 printf("u32=%d %d\n",
754 *(unsigned int *)&var1
, *(unsigned int *)&var2
);
755 *(char *)&var1
= 0x08;
756 printf("var1=%x\n", var1
);
757 *(short *)&var1
= 0x0809;
758 printf("var1=%x\n", var1
);
759 *(int *)&var1
= 0x08090a0b;
760 printf("var1=%x\n", var1
);
773 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
774 #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
776 static int toupper1(int a
)
783 int *s
, a
, b
, t
, f
, i
;
787 printf("!s=%d\n", !s
);
793 printf("a=%d %d %d\n", 0 || 0, 0 || 1, 1 || 1);
794 printf("a=%d %d %d\n", 0 && 0, 0 && 1, 1 && 1);
795 printf("a=%d %d\n", 1 ? 1 : 0, 0 ? 1 : 0);
810 printf("b=%d\n", a
+ (0 ? 1 : a
/ 2));
812 /* test register spilling */
815 a
= (a
+ b
) * ((a
< b
) ?
816 ((b
- a
) * (a
- b
)): a
+ b
);
819 /* test complex || or && expressions */
823 printf("exp=%d\n", f
== (32 <= a
&& a
<= 3));
824 printf("r=%d\n", (t
|| f
) + (t
&& f
));
829 int aspect_native
= 65536;
830 double bfu_aspect
= 1.0;
832 for(aspect_on
= 0; aspect_on
< 2; aspect_on
++) {
833 aspect
=aspect_on
?(aspect_native
*bfu_aspect
+0.5):65535UL;
834 printf("aspect=%d\n", aspect
);
838 /* again complex expression */
840 if (toupper1 (i
) != TOUPPER (i
))
841 printf("error %d\n", i
);
847 int *cinit2
= (int []){3, 2, 1};
849 void compound_literal_test(void)
854 printf("compound_test:\n");
856 p
= (int []){1, 2, 3};
862 printf("%d", cinit2
[i
]);
866 printf("q1=%s\n", q
);
868 q
= (char *){ "tralala2" };
869 printf("q2=%s\n", q
);
872 printf("q3=%s\n", q3
);
874 q
= (char []){ "tralala3" };
875 printf("q4=%s\n", q
);
878 p
= (int []){1, 2, cinit1
+ 3};
884 p
= (int []){1, 2, 4 + i
};
907 printf("kr_test:\n");
908 printf("func1=%d\n", kr_func1(3, 4));
909 printf("func2=%d\n", kr_func2(3, 4));
916 tab
= (char*)malloc(20);
932 /* structure assignment tests */
938 struct structa1 ssta1
;
940 void struct_assign_test1(struct structa1 s1
, int t
)
942 printf("%d %d %d\n", s1
.f1
, s1
.f2
, t
);
945 struct structa1
struct_assign_test2(struct structa1 s1
, int t
)
952 void struct_assign_test(void)
954 struct structa1 lsta1
, lsta2
;
957 printf("struct_assign_test:\n");
961 printf("%d %d\n", lsta1
.f1
, lsta1
.f2
);
963 printf("%d %d\n", lsta2
.f1
, lsta2
.f2
);
968 struct_assign_test1(lsta2
, 3);
970 printf("before call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
971 lsta2
= struct_assign_test2(lsta2
, 4);
972 printf("after call: %d %d\n", lsta2
.f1
, lsta2
.f2
);
975 /* casts to short/char */
977 void cast1(char a
, short b
, unsigned char c
, unsigned short d
)
979 printf("%d %d %d %d\n", a
, b
, c
, d
);
991 printf("cast_test:\n");
995 printf("%d %d %d %d\n",
998 (unsigned char)(a
+ 1),
999 (unsigned short)(a
+ 1));
1000 printf("%d %d %d %d\n",
1003 (unsigned char)0xfffff,
1004 (unsigned short)0xfffff);
1006 a
= (bcast
= 128) + 1;
1008 a
= (scast
= 65536) + 1;
1011 printf("sizeof(c) = %d, sizeof((int)c) = %d\n", sizeof(c
), sizeof((int)c
));
1013 /* test implicit int casting for array accesses */
1017 printf("%d %d\n", tab
[0], tab
[1]);
1019 /* test implicit casting on some operators */
1020 printf("sizeof(+(char)'a') = %d\n", sizeof(+(char)'a'));
1021 printf("sizeof(-(char)'a') = %d\n", sizeof(-(char)'a'));
1022 printf("sizeof(~(char)'a') = %d\n", sizeof(-(char)'a'));
1025 /* initializers tests */
1026 struct structinit1
{
1035 int sinit3
[3] = { 1, 2, {{3}}, };
1036 int sinit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1037 int sinit5
[3][2] = { 1, 2, 3, 4, 5, 6 };
1038 int sinit6
[] = { 1, 2, 3 };
1039 int sinit7
[] = { [2] = 3, [0] = 1, 2 };
1040 char sinit8
[] = "hello" "trala";
1042 struct structinit1 sinit9
= { 1, 2, 3 };
1043 struct structinit1 sinit10
= { .f2
= 2, 3, .f1
= 1 };
1044 struct structinit1 sinit11
= { .f2
= 2, 3, .f1
= 1,
1052 char *sinit12
= "hello world";
1058 char sinit14
[10] = { "abc" };
1059 int sinit15
[3] = { sizeof(sinit15
), 1, 2 };
1061 struct { int a
[3], b
; } sinit16
[] = { { 1 }, 2 };
1071 void init_test(void)
1075 int linit4
[3][2] = { {1, 2}, {3, 4}, {5, 6} };
1076 int linit6
[] = { 1, 2, 3 };
1078 char linit8
[] = "hello" "trala";
1079 int linit12
[10] = { 1, 2 };
1080 int linit13
[10] = { 1, 2, [7] = 3, [3] = 4, };
1081 char linit14
[10] = "abc";
1082 int linit15
[10] = { linit1
, linit1
+ 1, [6] = linit1
+ 2, };
1083 struct linit16
{ int a1
, a2
, a3
, a4
; } linit16
= { 1, .a3
= 2 };
1084 int linit17
= sizeof(linit17
);
1086 printf("init_test:\n");
1088 printf("sinit1=%d\n", sinit1
);
1089 printf("sinit2=%d\n", sinit2
);
1090 printf("sinit3=%d %d %d %d\n",
1096 printf("sinit6=%d\n", sizeof(sinit6
));
1097 printf("sinit7=%d %d %d %d\n",
1103 printf("sinit8=%s\n", sinit8
);
1104 printf("sinit9=%d %d %d\n",
1109 printf("sinit10=%d %d %d\n",
1114 printf("sinit11=%d %d %d %d %d %d\n",
1125 printf("[%d][%d] = %d %d %d\n",
1126 i
, j
, sinit4
[i
][j
], sinit5
[i
][j
], linit4
[i
][j
]);
1127 printf("linit1=%d\n", linit1
);
1128 printf("linit2=%d\n", linit2
);
1129 printf("linit6=%d\n", sizeof(linit6
));
1130 printf("linit8=%d %s\n", sizeof(linit8
), linit8
);
1132 printf("sinit12=%s\n", sinit12
);
1133 printf("sinit13=%d %s %s %s\n",
1138 printf("sinit14=%s\n", sinit14
);
1140 for(i
=0;i
<10;i
++) printf(" %d", linit12
[i
]);
1142 for(i
=0;i
<10;i
++) printf(" %d", linit13
[i
]);
1144 for(i
=0;i
<10;i
++) printf(" %d", linit14
[i
]);
1146 for(i
=0;i
<10;i
++) printf(" %d", linit15
[i
]);
1148 printf("%d %d %d %d\n",
1153 /* test that initialisation is done after variable declare */
1154 printf("linit17=%d\n", linit17
);
1155 printf("sinit15=%d\n", sinit15
[0]);
1156 printf("sinit16=%d %d\n", sinit16
[0].a
[0], sinit16
[1].a
[0]);
1157 printf("sinit17=%s %d %s %d\n",
1158 sinit17
[0].s
, sinit17
[0].len
,
1159 sinit17
[1].s
, sinit17
[1].len
);
1186 /* ISOC99 _Bool type */
1187 void c99_bool_test(void)
1193 printf("bool_test:\n");
1194 printf("sizeof(_Bool) = %d\n", sizeof(_Bool
));
1196 printf("cast: %d %d %d\n", (_Bool
)10, (_Bool
)0, (_Bool
)a
);
1198 printf("b = %d\n", b
);
1200 printf("b = %d\n", b
);
1204 void bitfield_test(void)
1214 unsigned int f5
: 7;
1216 printf("bitfield_test:");
1217 printf("sizeof(st1) = %d\n", sizeof(st1
));
1226 printf("%d %d %d %d %d\n",
1227 st1
.f1
, st1
.f2
, st1
.f3
, st1
.f4
, st1
.f5
);
1230 #define FTEST(prefix, type, fmt)\
1231 void prefix ## cmp(type a, type b)\
1233 printf("%d %d %d %d %d %d\n",\
1240 printf(fmt " " fmt " " fmt " " fmt " " fmt " " fmt " " fmt "\n",\
1248 printf(fmt "\n", ++a);\
1249 printf(fmt "\n", a++);\
1250 printf(fmt "\n", a);\
1252 void prefix ## fcast(type a)\
1263 printf("ftof: %f %f %Lf\n", fa, da, la);\
1265 ua = (unsigned int)a;\
1266 printf("ftoi: %d %u\n", ia, ua);\
1270 printf("itof: " fmt "\n", b);\
1272 printf("utof: " fmt "\n", b);\
1275 void prefix ## test(void)\
1277 printf("testing '%s'\n", #type);\
1278 prefix ## cmp(1, 2.5);\
1279 prefix ## cmp(2, 1.5);\
1280 prefix ## cmp(1, 1);\
1281 prefix ## fcast(234.6);\
1282 prefix ## fcast(-2334.6);\
1285 FTEST(f
, float, "%f")
1286 FTEST(d
, double, "%f")
1287 FTEST(ld
, long double, "%Lf")
1289 double ftab1
[3] = { 1.2, 3.4, -5.6 };
1292 void float_test(void)
1299 printf("float_test:\n");
1300 printf("sizeof(float) = %d\n", sizeof(float));
1301 printf("sizeof(double) = %d\n", sizeof(double));
1302 printf("sizeof(long double) = %d\n", sizeof(long double));
1306 printf("%f %f %f\n", ftab1
[0], ftab1
[1], ftab1
[2]);
1307 printf("%f %f %f\n", 2.12, .5, 2.3e10
);
1308 // printf("%f %f %f\n", 0x1234p12, 0x1e23.23p10, 0x12dp-10);
1310 printf("da=%f\n", da
);
1312 printf("fa=%f\n", fa
);
1315 printf("da = %f\n", da
);
1318 printf("db = %f\n", db
);
1326 return fib(n
-1) + fib(n
-2);
1338 printf("funcptr:\n");
1345 /* more complicated pointer computation */
1348 printf("sizeof1 = %d\n", sizeof(funcptr_test
));
1349 printf("sizeof2 = %d\n", sizeof funcptr_test
);
1350 printf("sizeof3 = %d\n", sizeof(&funcptr_test
));
1351 printf("sizeof4 = %d\n", sizeof &funcptr_test
);
1354 void lloptest(long long a
, long long b
)
1356 unsigned long long ua
, ub
;
1361 printf("arith: %Ld %Ld %Ld\n",
1367 printf("arith1: %Ld %Ld\n",
1373 printf("bin: %Ld %Ld %Ld\n",
1379 printf("test: %d %d %d %d %d %d\n",
1387 printf("utest: %d %d %d %d %d %d\n",
1398 printf("arith2: %Ld %Ld\n", a
, b
);
1399 printf("arith2: %Ld %Ld\n", a
++, b
++);
1400 printf("arith2: %Ld %Ld\n", --a
, --b
);
1401 printf("arith2: %Ld %Ld\n", a
, b
);
1404 void llshift(long long a
, int b
)
1406 printf("shift: %Ld %Ld %Ld\n",
1407 (unsigned long long)a
>> b
,
1410 printf("shiftc: %Ld %Ld %Ld\n",
1411 (unsigned long long)a
>> 3,
1414 printf("shiftc: %Ld %Ld %Ld\n",
1415 (unsigned long long)a
>> 35,
1425 long long la
, lb
, lc
;
1426 unsigned long long ula
, ulb
, ulc
;
1429 la
= (la
<< 20) | 0x12345;
1431 printf("la=%Ld ula=%Lu\n", la
, ula
);
1436 printf("lltof: %f %f %Lf\n", fa
, da
, lda
);
1441 printf("ftoll: %Ld %Ld %Ld\n", la
, lb
, lc
);
1446 printf("ulltof: %f %f %Lf\n", fa
, da
, lda
);
1451 printf("ftoull: %Lu %Lu %Lu\n", ula
, ulb
, ulc
);
1454 long long llfunc1(int a
)
1464 long long int value(struct S
*v
)
1466 return ((long long int)v
->item
);
1469 void longlong_test(void)
1474 printf("longlong_test:\n");
1475 printf("sizeof(long long) = %d\n", sizeof(long long));
1480 printf("%Ld %Ld\n", a
, b
);
1481 printf("%Ld %Ld %Ld %Lx\n",
1485 0x1234567812345679);
1490 lloptest(0xff, 0x1234);
1491 b
= 0x72345678 << 10;
1495 b
= 0x72345678LL
<< 10;
1506 /* long long reg spill test */
1511 printf("%lld\n", value(&a
));
1513 lloptest(0x80000000, 0);
1516 void vprintf1(const char *fmt
, ...)
1538 i
= va_arg(ap
, int);
1542 d
= va_arg(ap
, double);
1546 ll
= va_arg(ap
, long long);
1560 void stdarg_test(void)
1562 vprintf1("%d %d %d\n", 1, 2, 3);
1563 vprintf1("%f %d %f\n", 1.0, 2, 3.0);
1564 vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0);
1567 void whitespace_test(void)
1573 ntf("whitspace:\n");\f\v
1582 printf("len1=%d\n", strlen("
1586 printf("len1=%d str[0]=%d\n", strlen(str
), str
[0]);
1587 printf("len1=%d\n", strlen("
a
1591 int reltab
[3] = { 1, 2, 3 };
1593 int *rel1
= &reltab
[1];
1594 int *rel2
= &reltab
[2];
1596 void relocation_test(void)
1598 printf("*rel1=%d\n", *rel1
);
1599 printf("*rel2=%d\n", *rel2
);
1602 void old_style_f(a
,b
,c
)
1606 printf("a=%d b=%d b=%f\n", a
, b
, c
);
1609 void old_style_function(void)
1611 old_style_f((void *)1, 2, 3.0);
1614 void sizeof_test(void)
1619 printf("sizeof(int) = %d\n", sizeof(int));
1620 printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int));
1621 printf("sizeof(short) = %d\n", sizeof(short));
1622 printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short));
1623 printf("sizeof(char) = %d\n", sizeof(char));
1624 printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char));
1625 printf("sizeof(func) = %d\n", sizeof sizeof_test());
1627 printf("sizeof(a++) = %d\n", sizeof a
++);
1628 printf("a=%d\n", a
);
1630 printf("sizeof(**ptr) = %d\n", sizeof (**ptr
));
1632 /* some alignof tests */
1633 printf("__alignof__(int) = %d\n", __alignof__(int));
1634 printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));
1635 printf("__alignof__(short) = %d\n", __alignof__(short));
1636 printf("__alignof__(unsigned short) = %d\n", __alignof__(unsigned short));
1637 printf("__alignof__(char) = %d\n", __alignof__(char));
1638 printf("__alignof__(unsigned char) = %d\n", __alignof__(unsigned char));
1639 printf("__alignof__(func) = %d\n", __alignof__
sizeof_test());
1642 void typeof_test(void)
1651 printf("a=%f b=%f c=%f\n", a
, b
, c
);