Unified · Split
| @@ -57,6 +57,9 @@ void bitfield_test(void); · 56 unmodified lines | ||
| 57 | 57 | void c99_bool_test(void); |
| 58 | 58 | void float_test(void); |
| 59 | 59 | void longlong_test(void); |
| 60 | +void stdarg_test(void); | |
| 61 | +void whitespace_test(void); | |
| 62 | +void relocation_test(void); | |
| 60 | 63 | |
| 61 | 64 | int fib(int n); |
| 62 | 65 | void num(int n); |
| @@ -101,7 +104,7 @@ int isid(int c); · 38 unmodified lines | ||
| 101 | 104 | |
| 102 | 105 | void macro_test() |
| 103 | 106 | { |
| 104 | − printf("macro:\n"); | |
| 107 | + printf("macro:\n"); | |
| 105 | 108 | pf("N=%d\n", N); |
| 106 | 109 | printf("aaa=%d\n", AAA); |
| 107 | 110 | |
| @@ -174,6 +177,10 @@ void macro_test() · 66 unmodified lines | ||
| 174 | 177 | |
| 175 | 178 | MACRO_NOARGS(); |
| 176 | 179 | |
| 180 | +#ifdef __LINE__ | |
| 181 | + printf("__LINE__ defined\n"); | |
| 182 | +#endif | |
| 183 | + | |
| 177 | 184 | printf("__LINE__=%d __FILE__=%s\n", |
| 178 | 185 | __LINE__, __FILE__); |
| 179 | 186 | #line 200 |
| @@ -192,6 +199,9 @@ void macro_test() · 12 unmodified lines | ||
| 192 | 199 | dprintf1(1, "vaarg1\n"); |
| 193 | 200 | dprintf1(1, "vaarg1=%d\n", 2); |
| 194 | 201 | dprintf1(1, "vaarg1=%d %d\n", 1, 2); |
| 202 | + | |
| 203 | + /* gcc extension */ | |
| 204 | + printf("func='%s'\n", __FUNCTION__); | |
| 195 | 205 | } |
| 196 | 206 | |
| 197 | 207 | int op(a,b) |
| @@ -409,6 +419,9 @@ int main(int argc, char **argv) · 211 unmodified lines | ||
| 409 | 419 | c99_bool_test(); |
| 410 | 420 | float_test(); |
| 411 | 421 | longlong_test(); |
| 422 | + stdarg_test(); | |
| 423 | + whitespace_test(); | |
| 424 | + relocation_test(); | |
| 412 | 425 | return 0; |
| 413 | 426 | } |
| 414 | 427 | |
| @@ -1362,3 +1375,88 @@ void longlong_test(void) · 947 unmodified lines | ||
| 1362 | 1375 | #endif |
| 1363 | 1376 | } |
| 1364 | 1377 | |
| 1378 | +void vprintf1(const char *fmt, ...) | |
| 1379 | +{ | |
| 1380 | + va_list ap; | |
| 1381 | + const char *p; | |
| 1382 | + int c, i; | |
| 1383 | + double d; | |
| 1384 | + long long ll; | |
| 1385 | + | |
| 1386 | + va_start(ap, fmt); | |
| 1387 | + | |
| 1388 | + p = fmt; | |
| 1389 | + for(;;) { | |
| 1390 | + c = *p; | |
| 1391 | + if (c == '\0') | |
| 1392 | + break; | |
| 1393 | + p++; | |
| 1394 | + if (c == '%') { | |
| 1395 | + c = *p; | |
| 1396 | + switch(c) { | |
| 1397 | + case '\0': | |
| 1398 | + goto the_end; | |
| 1399 | + case 'd': | |
| 1400 | + i = va_arg(ap, int); | |
| 1401 | + printf("%d", i); | |
| 1402 | + break; | |
| 1403 | + case 'f': | |
| 1404 | + d = va_arg(ap, double); | |
| 1405 | + printf("%f", d); | |
| 1406 | + break; | |
| 1407 | + case 'l': | |
| 1408 | + ll = va_arg(ap, long long); | |
| 1409 | + printf("%Ld", ll); | |
| 1410 | + break; | |
| 1411 | + } | |
| 1412 | + p++; | |
| 1413 | + } else { | |
| 1414 | + putchar(c); | |
| 1415 | + } | |
| 1416 | + } | |
| 1417 | + the_end: | |
| 1418 | + va_end(ap); | |
| 1419 | +} | |
| 1420 | + | |
| 1421 | + | |
| 1422 | +void stdarg_test(void) | |
| 1423 | +{ | |
| 1424 | + vprintf1("%d %d %d\n", 1, 2, 3); | |
| 1425 | + vprintf1("%f %d %f\n", 1.0, 2, 3.0); | |
| 1426 | + vprintf1("%l %l %d %f\n", 1234567891234LL, 987654321986LL, 3, 1234.0); | |
| 1427 | +} | |
| 1428 | + | |
| 1429 | +void whitespace_test(void) | |
| 1430 | +{ | |
| 1431 | + char *str; | |
| 1432 | + | |
| 1433 | + #if 1 | |
| 1434 | + pri\ | |
| 1435 | +ntf("whitspace:\n"); | |
| 1436 | +#endif | |
| 1437 | + pf("N=%d\n", 2); | |
| 1438 | + pri\ | |
| 1439 | +ntf("aaa=%d\n", 3); | |
| 1440 | + | |
| 1441 | + pri\ | |
| 1442 | +\ | |
| 1443 | +ntf("min=%d\n", 4); | |
| 1444 | + printf("len1=%d\n", strlen(" | |
| 1445 | +")); | |
| 1446 | + str = " | |
| 1447 | +"; | |
| 1448 | + printf("len1=%d str[0]=%d\n", strlen(str), str[0]); | |
| 1449 | + printf("len1=%d\n", strlen(" a | |
| 1450 | +")); | |
| 1451 | +} | |
| 1452 | + | |
| 1453 | +int reltab[3] = { 1, 2, 3 }; | |
| 1454 | + | |
| 1455 | +int *rel1 = &reltab[1]; | |
| 1456 | +int *rel2 = &reltab[2]; | |
| 1457 | + | |
| 1458 | +void relocation_test(void) | |
| 1459 | +{ | |
| 1460 | + printf("*rel1=%d\n", *rel1); | |
| 1461 | + printf("*rel2=%d\n", *rel2); | |
| 1462 | +} | |