This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Add __auto_type C extension, use it in <stdatomic.h>
- From: Basile Starynkevitch <basile at starynkevitch dot net>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 13 Nov 2013 21:43:33 +0100
- Subject: Re: Add __auto_type C extension, use it in <stdatomic.h>
- Authentication-results: sourceware.org; auth=none
- References: <Pine dot LNX dot 4 dot 64 dot 1311130038460 dot 6467 at digraph dot polyomino dot org dot uk> <CAFiYyc3F7m6KkJbTf3fXtKMhF4TMbpiiJSYh6tdbtNs6t6EwrA at mail dot gmail dot com>
On Wed, 2013-11-13 at 11:39 +0100, Richard Biener wrote:
> On Wed, Nov 13, 2013 at 1:39 AM, Joseph S. Myers
> <joseph@codesourcery.com> wrote:
> > <stdatomic.h> contains what C11 describes as "generic functions".
> > Although DR#419 makes clear that users cannot #undef these macros (or
> > otherwise suppress use of a macro definition) and expect to find an
> > underlying function, they still need to behave like functions as
> > regards evaluating their arguments exactly once (see C11 7.1.4).
> >
> > I noted when adding <stdatomic.h> to mainline that some of the macro
> > definitions there failed that requirement in the case where the
> > pointer argument had variably modified type, because then typeof
> > evaluates its argument and so that argument would be evaluated twice.
> > Avoiding such double evaluation requires defining the type of a
> > temporary variable, and initializing it with the pointer argument,
> > with a single evaluation. To achieve this, this patch adds a new GNU
> > C extension __auto_type, essentially a restricted version of C++11
> > auto, and uses it in <stdatomic.h>.
>
> I suppose you didn't use '__auto' because that's much more likely
> used elsewhere than '__auto_type'?
I have no idea, but does anyone knows if other free compilers (notably
Clang/LLVM) are adding a similar feature?
If they do, perhaps (if it is not too painful) we should use the same
keyword (i.e. __auto_type) and a similar semantics.
And I also like that feature, but it should be documented outside of the
support of <stdatomic.h> since it is genuinely useful by itself (e.g. as
an alternative to typeof).
Regards.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***