History

Add -std=c11 option which sets __STDC_VERSION__ to 201112L and allows to implement c11 features conditionally

Christian Jullien committed 7 years ago

Commit a3a29171 parent 337dc843 files · +14 −2Browse files

Unified · Split

3 files
  1. libtcc.c +11 −2
  2. tcc.c +2 −0
  3. tcc.h +1 −0
libtcc.c+11−2
@@ -733,6 +733,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 732 unmodified lines
733733 ++nb_states;
734734
735735 s->nocommon = 1;
736+ s->cversion = 199901; /* default unless -std=c11 is supplied */
736737 s->warn_implicit_function_declaration = 1;
737738 s->ms_extensions = 1;
738739
@@ -1790,8 +1791,16 @@ reparse: · 1051 unmodified lines
17901791 s->static_link = 1;
17911792 break;
17921793 case TCC_OPTION_std:
1793− /* silently ignore, a current purpose:
1794− allow to use a tcc as a reference compiler for "make test" */
1794+ if (*optarg == '=') {
1795+ ++optarg;
1796+ if (strcmp(optarg, "c11") == 0) {
1797+ tcc_undefine_symbol(s, "__STDC_VERSION__");
1798+ tcc_define_symbol(s, "__STDC_VERSION__", "201112L");
1799+ s->cversion = 201112;
1800+ }
1801+ }
1802+ /* silently ignore other values, a current purpose:
1803+ allow to use a tcc as a reference compiler for "make test" */
17951804 break;
17961805 case TCC_OPTION_shared:
17971806 x = TCC_OUTPUT_DLL;
tcc.c+2−0
@@ -33,6 +33,8 @@ static const char help[] = · 32 unmodified lines
3333 " -o outfile set output filename\n"
3434 " -run run compiled source\n"
3535 " -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n"
36+ " -std=c99 Conform to the ISO 1999 C standard (default).\n"
37+ " -std=c11 Conform to the ISO 2011 C standard.\n"
3638 " -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n"
3739 " -w disable all warnings\n"
3840 " -v -vv show version, show search paths or loaded files\n"
tcc.h+1−0
@@ -651,6 +651,7 @@ struct TCCState { · 650 unmodified lines
651651 int rdynamic; /* if true, all symbols are exported */
652652 int symbolic; /* if true, resolve symbols in the current module first */
653653 int filetype; /* file type for compilation (NONE,C,ASM) */
654+ int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */
654655
655656 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
656657 char *soname; /* as specified on the command line (-soname) */

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