C vs. C++ parsers and the __attribute__ syntax

Joseph S. Myers jsm@polyomino.org.uk
Wed Oct 27 16:50:00 GMT 2004


On Wed, 27 Oct 2004, Ulrich Weigand wrote:

> > > typedef struct test * __attribute__ ((mode (SI))) test_ptr32;
> > 
> > This is the proper way.
> 
> So it's a bug that the C++ parser doesn't handle this correctly?
> I'll open a PR if so.

I'd consider it a bug.

> > > How would I declare a type like 'an SImode pointer to a
> > > TImode integer'?
> > 
> > typedef int (__attribute__((mode(TI))) (*__attribute__((mode(SI))) type));
> 
> This works for C; the C++ parser appears to go into an
> endless loop when given this code ...

An endless loop is certainly a bug, regardless of the validity of the 
code.

> Without the outer pair of parentheses, the C compiler says
> error: invalid pointer mode 'TI'
> I guess this is because of the compatibility issues mentioned
> in the last paragraph of the above manual page?

Indeed, without the outer parentheses the TI attribute applies to the 
declaration as a whole, and so gets adjusted to apply to the (pointer) 
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)



More information about the Gcc mailing list