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

This commit is contained in:
Christian Jullien 2019-01-10 14:41:54 +01:00 committed by Pursuer
parent 337dc84b57
commit a3a291784a
3 changed files with 14 additions and 2 deletions

View File

@ -733,6 +733,7 @@ LIBTCCAPI TCCState *tcc_new(void)
++nb_states;
s->nocommon = 1;
s->cversion = 199901; /* default unless -std=c11 is supplied */
s->warn_implicit_function_declaration = 1;
s->ms_extensions = 1;
@ -1790,8 +1791,16 @@ reparse:
s->static_link = 1;
break;
case TCC_OPTION_std:
/* silently ignore, a current purpose:
allow to use a tcc as a reference compiler for "make test" */
if (*optarg == '=') {
++optarg;
if (strcmp(optarg, "c11") == 0) {
tcc_undefine_symbol(s, "__STDC_VERSION__");
tcc_define_symbol(s, "__STDC_VERSION__", "201112L");
s->cversion = 201112;
}
}
/* silently ignore other values, a current purpose:
allow to use a tcc as a reference compiler for "make test" */
break;
case TCC_OPTION_shared:
x = TCC_OUTPUT_DLL;

2
tcc.c
View File

@ -33,6 +33,8 @@ static const char help[] =
" -o outfile set output filename\n"
" -run run compiled source\n"
" -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n"
" -std=c99 Conform to the ISO 1999 C standard (default).\n"
" -std=c11 Conform to the ISO 2011 C standard.\n"
" -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n"
" -w disable all warnings\n"
" -v -vv show version, show search paths or loaded files\n"

1
tcc.h
View File

@ -651,6 +651,7 @@ struct TCCState {
int rdynamic; /* if true, all symbols are exported */
int symbolic; /* if true, resolve symbols in the current module first */
int filetype; /* file type for compilation (NONE,C,ASM) */
int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */
char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
char *soname; /* as specified on the command line (-soname) */