With this code, we can compile more projects, who expect gcc or clang as compiler. (-std=gnu11 used in Makefiles) As a further extension, it would be easy to disable gcc extensions
Unified · Split
| @@ -1565,6 +1565,23 @@ static const TCCOption tcc_options[] = { · 1564 unmodified lines | |||
| 1565 | { NULL, 0, 0 }, | 1565 | { NULL, 0, 0 }, |
| 1566 | }; | 1566 | }; |
| 1567 | 1567 | ||
| 1568 | typedef struct stdvalue { | ||
| 1569 | uint32_t cversion; | ||
| 1570 | const char * name; | ||
| 1571 | } stdvalue; | ||
| 1572 | |||
| 1573 | /* accepted values for the -std= option */ | ||
| 1574 | static const stdvalue std_values[] = { | ||
| 1575 | { 199901, "c99" }, | ||
| 1576 | { 201112, "c11" }, | ||
| 1577 | { 201710, "c17" }, | ||
| 1578 | { 202000, "c2x" }, | ||
| 1579 | { 199901, "gnu99" }, | ||
| 1580 | { 201112, "gnu11" }, | ||
| 1581 | { 201710, "gnu17" }, | ||
| 1582 | { 202000, "gnu2x" } | ||
| 1583 | }; | ||
| 1584 | |||
| 1568 | typedef struct FlagDef { | 1585 | typedef struct FlagDef { |
| 1569 | uint16_t offset; | 1586 | uint16_t offset; |
| 1570 | uint16_t flags; | 1587 | uint16_t flags; |
| @@ -1835,8 +1852,21 @@ reparse: · 264 unmodified lines | |||
| 1835 | s->static_link = 1; | 1852 | s->static_link = 1; |
| 1836 | break; | 1853 | break; |
| 1837 | case TCC_OPTION_std: | 1854 | case TCC_OPTION_std: |
| 1838 | if (strcmp(optarg, "=c11") == 0) | 1855 | x = 0; |
| 1839 | s->cversion = 201112; | 1856 | if (*optarg == '=') { |
| 1857 | do { | ||
| 1858 | if (strcmp(std_values[x].name, &optarg[1]) == 0) { | ||
| 1859 | x = std_values[x].cversion; | ||
| 1860 | } | ||
| 1861 | else | ||
| 1862 | ++x; | ||
| 1863 | } while (x < (sizeof(std_values)/sizeof(stdvalue))); | ||
| 1864 | } | ||
| 1865 | if (x > (sizeof(std_values)/sizeof(stdvalue))) | ||
| 1866 | s->cversion = x; | ||
| 1867 | else | ||
| 1868 | goto unsupported_option; | ||
| 1869 | |||
| 1840 | break; | 1870 | break; |
| 1841 | case TCC_OPTION_shared: | 1871 | case TCC_OPTION_shared: |
| 1842 | x = TCC_OUTPUT_DLL; | 1872 | x = TCC_OUTPUT_DLL; |