This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C vs. C++ parsers and the __attribute__ syntax
- From: "Joseph S. Myers" <jsm at polyomino dot org dot uk>
- To: Ulrich Weigand <weigand at i1 dot informatik dot uni-erlangen dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 27 Oct 2004 13:33:04 +0000 (UTC)
- Subject: Re: C vs. C++ parsers and the __attribute__ syntax
- References: <200410271314.i9RDEL5h030002@faui1g.informatik.uni-erlangen.de>
On Wed, 27 Oct 2004, Ulrich Weigand wrote:
> The question is now how to express this syntactically. Is there
> a document that formally specifies the syntax of the attribute
> extension? The info pages appear a bit vague ...
"Attribute Syntax" in the manual, but there may well be bugs in both the
documentation and the code.
> typedef struct test * __attribute__ ((mode (SI))) test_ptr32;
>
> would be the correct way to declare a SImode pointer type to
> 'struct test', if the placement of attribute is analogous to
> 'const' or 'volatile' -- it is 'test_ptr32' that is of mode
> SImode, not '*test_ptr32'.
>
> And indeed, this does have the effect I intended with the C
> parser. However, the C++ parser, while it accepts the above
> construct, appears to simply ignore the attribute.
This is the proper way.
> On the hand, *this* declaration:
>
> typedef struct test __attribute__ ((mode (SI))) *test_ptr32;
In this case, the attribute is part of the declaration specifiers, and
applies to the declaration as a whole. This form (and similarly postfix
attributes) is most cleanly used only for those attributes which act like
storage class specifiers in applying to declarations but not types.
However, many such forms are accepted for compatibility with existing code
and adjusted to apply to the type, or in the case of vector_size
attributes to some type nested within there.
> How would I declare a type like 'an SImode pointer to a
> TImode integer'?
typedef int (__attribute__((mode(TI))) (*__attribute__((mode(SI))) type));
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)