From a3a291784a9abac4edea5a10af69bc7275413cd2 Mon Sep 17 00:00:00 2001 From: Christian Jullien Date: Thu, 10 Jan 2019 14:41:54 +0100 Subject: [PATCH] Add -std=c11 option which sets __STDC_VERSION__ to 201112L and allows to implement c11 features conditionally --- libtcc.c | 13 +++++++++++-- tcc.c | 2 ++ tcc.h | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libtcc.c b/libtcc.c index df7adabc..5467731f 100644 --- a/libtcc.c +++ b/libtcc.c @@ -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; diff --git a/tcc.c b/tcc.c index f780389b..2d4e1eab 100644 --- a/tcc.c +++ b/tcc.c @@ -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" diff --git a/tcc.h b/tcc.h index 165249fe..61c1b43c 100644 --- a/tcc.h +++ b/tcc.h @@ -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) */