[cfe-dev] Attributes on statements and expressions

Trevor Harmon Trevor.W.Harmon at nasa.gov
Mon Apr 26 14:34:06 PDT 2010


On Apr 26, 2010, at 12:40 AM, Olaf Krzikalla wrote:

> To be honest I don't like the GCC syntax and - given an proposal  
> already
> accepted for standardization - I wouldn't bother implementing it but  
> go
> straight for the new [[attribute]] syntax.

Actually I wasn't even aware of the new [[attribute]] syntax. (I've  
not been following the C++0x effort.) I only mentioned __attribute__  
because that seemed to the planned approach in the original discussion  
I referenced.

The new [[attribute]] stuff looks cool; it's exactly what I need. In  
particular it allows attributes on loops, such as:

for [[ attr1 ]] (int i=0; i<num_elem; i++) {process (list_items[i]); }

The fact that it's going to be a standard makes it all the better.

For those interested in reading about it, the best material I've been  
able to find so far is this:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2418.pdf

It's a little old but provides a good overview.

There's one thing I'm confused about, though. I assume it's possible  
to define my own attributes, e.g. [[mycoolattr(42)]]. But how exactly  
do I do that? Is there some sample code somewhere?

Trevor




More information about the cfe-dev mailing list