Helper macros to make the attribute syntax in GCC cleaner.
Declaring a vector type:
typedef float V4SF __attribute__ ((__vector_size__(16)));
Becomes:
typedef float V4SF GATTRIB(vector_size(16));
Forcing a function to always be inline:
inline float __attribute__ ((__always_inline__)) add(float a, float b)
{
return a + b;
}
Becomes:
inline float GATTRIB(always_inline) add(float a, float b)
{
return a + b;
}
To specify more than one attribute, append an S
to the macro name so that GATTRIB
becomes GATTRIBS
.
For example:
inline void __attribute__ ((__always_inline__, __nonnull__(1), __nothrow__, __unused__)) set_memory(void * ptr, int value, size_t num)
{
memset(ptr, value, num);
}
Becomes:
inline void GATTRIBS(always_inline, nonnull(1), nothrow, unused) set_memory(void * ptr, int value, size_t num)
{
memset(ptr, value, num);
}
- If you need extra attributes other than the one's included then feel free to create macros for them.
- To add a new attribute you create a macro prefixed with
GATTRIB_
.- For example:
#define GATTRIB_someattr __theattr__
- For example:
- To add a new attribute you create a macro prefixed with
- The
GATTRIBS
macro supports up to 8 parameters. You must modify it if you need more than 8 attributes. Should be fairly easy. - There's also a shorter alias called
GATTR
included for convenience.