Don't worry Matthias, this how we can make a better tcc. Thank you for the revert.
-----Original Message----- From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of uso ewin Sent: vendredi 11 janvier 2019 10:41 To: tinycc-devel@nongnu.org Subject: Re: [Tinycc-devel] Add max_align_t to stddef.h and C11 On Fri, Jan 11, 2019 at 7:56 AM Christian Jullien <eli...@orange.fr> wrote: > > Petr, I also agree with you. > > If gcc more or less "governs" tcc behavior, _Alignof and _Generic should be > defined by default whatever -std=cxx is used. > > Here is a quick test I've made. > > #include <stdio.h> > > #define tt(X) _Generic((X), \ > int: "int", \ > default: "other") > > int > main() { > printf("__STDC_VERSION__ %d\n", __STDC_VERSION__); > printf("_Alignof(double) %d\n", _Alignof(double)); > printf("_Generic(int) %s\n", tt(42)); > } > > [cjullien@hilbert ~]$ gcc -std=c11 foo.c -o foo && ./foo > __STDC_VERSION__ 201112 > _Alignof(double) 8 > _Generic(int) int > [cjullien@hilbert ~]$ gcc -std=c99 foo.c -o foo && ./foo > __STDC_VERSION__ 199901 > _Alignof(double) 8 > _Generic(int) int > > You can see that with -std=c99 the two macros are available > > Only -pedantic flag makes gcc protest > > [cjullien@hilbert ~]$ gcc -std=c99 -pedantic foo.c -o foo && ./foo > foo.c: In function 'main': > foo.c:10:35: warning: ISO C99 does not support '_Alignof' [-Wpedantic] > printf("_Alignof(double) %d\n", _Alignof(double)); > ^~~~~~~~ > foo.c:3:15: warning: ISO C99 does not support '_Generic' [-Wpedantic] > #define tt(X) _Generic((X), \ > ^~~~~~~~ > > > -----Original Message----- > From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] > On Behalf Of Petr Skocík > Sent: vendredi 11 janvier 2019 00:05 > To: tinycc-devel@nongnu.org > Subject: Re: [Tinycc-devel] Add max_align_t to stddef.h and C11 > > Having __STDC_VERSION__ reflect the -std= command option is great. > However, I think that disallowing _Generic and _Alignof at lower > versions is unnecessarily pedantic (as in a behavior more suitable for > compiler runs invoked with `-pedantic`). Unlike max_align_t, _Generic > and _Alignof are reserved identifiers in any C version. They shouldn't > ever need to be hidden. Hiding them can unnecessarily break some project > builds that use tcc with _Generic or _Alignof and without -std=c11. > > Petr S. > > > On 1/10/19 11:47 PM, uso ewin wrote: > > On Thu, Jan 10, 2019 at 2:47 PM Christian Jullien <eli...@orange.fr> > wrote: > >> > >> Matthias, > >> > >> > >> I'm happy you like my patch. I was waiting for comments before pushing > this > >> patch. > >> As you said, no one protested (or care), so it is committed in mod. > >> > >> It let you add the logic for the C11. > >> > >> Christian > >> > >> -----Original Message----- > >> From: Tinycc-devel > [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] > >> On Behalf Of uso ewin > >> Sent: jeudi 10 janvier 2019 11:13 > >> To: tinycc-devel@nongnu.org > >> Subject: Re: [Tinycc-devel] Add max_align_t to stddef.h and C11 > >> > >> On Tue, Jan 8, 2019 at 6:02 PM Christian Jullien <eli...@orange.fr> > wrote: > >>> > >>>> Maybe add a global variable > >>> > >>> Not global but a new member of TCCState, for example cversion > >>> > >>> If (s->cversion >= 201112) { > >>> /* Hello C11 */ > >>> } > >>> > >>> Diff becomes: > >>> > >>> jullien@sims3:~/new-tcc $ git diff > >>> diff --git a/libtcc.c b/libtcc.c > >>> index df7adab..7883734 100644 > >>> --- a/libtcc.c > >>> +++ b/libtcc.c > >>> @@ -1790,8 +1790,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 f780389..2d4e1ea 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 cc85291..8416cc5 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, either 0 (199901), > 201112, > >>> ... */ > >>> > >>> char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ > >>> char *soname; /* as specified on the command line (-soname) */ > >>> > >>> > >>> > >>> _______________________________________________ > >>> Tinycc-devel mailing list > >>> Tinycc-devel@nongnu.org > >>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel > >> > >> I like the version with cversion in tcc state. > >> > >> As no one protest, I guess you can push. > >> Do you want to patch existing C11 code too ? > >> if not I can do it, but I need this patch to be merge. > >> > >> Matthias, > >> > >> _______________________________________________ > >> Tinycc-devel mailing list > >> Tinycc-devel@nongnu.org > >> https://lists.nongnu.org/mailman/listinfo/tinycc-devel > >> > >> > >> _______________________________________________ > >> Tinycc-devel mailing list > >> Tinycc-devel@nongnu.org > >> https://lists.nongnu.org/mailman/listinfo/tinycc-devel > > > > Hi, > > > > I've push the patch to allow _Alignof and _Generic only when -std=c11 is > use. > > > > Matthias, > > > > _______________________________________________ > > Tinycc-devel mailing list > > Tinycc-devel@nongnu.org > > https://lists.nongnu.org/mailman/listinfo/tinycc-devel > > > > > _______________________________________________ > Tinycc-devel mailing list > Tinycc-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/tinycc-devel > > > _______________________________________________ > Tinycc-devel mailing list > Tinycc-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/tinycc-devel Ok, I've revert my change, Sorry for the bug matthias _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel