History

libtcc: Allow more values for the -std= option

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

Detlef Riekenberg committed 4 years ago

Commit b3bebdb1 parent 8759b251 file · +32 −2Browse files

Unified · Split

libtcc.c+32−2
@@ -1565,6 +1565,23 @@ static const TCCOption tcc_options[] = { · 1564 unmodified lines
15651565 { NULL, 0, 0 },
15661566 };
15671567
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+
15681585 typedef struct FlagDef {
15691586 uint16_t offset;
15701587 uint16_t flags;
@@ -1835,8 +1852,21 @@ reparse: · 264 unmodified lines
18351852 s->static_link = 1;
18361853 break;
18371854 case TCC_OPTION_std:
1838− if (strcmp(optarg, "=c11") == 0)
1839− s->cversion = 201112;
1855+ x = 0;
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+
18401870 break;
18411871 case TCC_OPTION_shared:
18421872 x = TCC_OUTPUT_DLL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t