I found that a lot of compilers just do not support __attribute__
.
#if defined (__GNUC__)
short xxxyyy[aaa_SIZE]__attribute__ ((aligned (32)));
#endif
or even
#ifndef __attribute__(x)
#define __attribute__(x)
#endif
As far as I know, GNUC is the only one supporting this __attribute__
— is that correct?
And is it reasonable general practice to use macros like above?
Is there any C standard that supports this? Or is there any better approach?
New C standard (C23 — working draft) added attributes in [[attribute]]
format. It is portable. They are already a part of C++ since C++11.
Example:
[[noreturn]] void f(void) {
abort(); // ok
}
All older C standards do not have it and they are compiler extensions. Do not use them unless you really need them (for example writing low-level hardware stuff).
If such a program has to be compiled by many compilers you will need plenty #if
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With