R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215193

Is there a list of minimum gcc version supporting each __attribute__?

The official documentation here only lists the minimum required version for a very small number of attributes:

http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

Is there a complete list of which version each attribute was added in? Even better would be a list that also shows which ones are compatible with pcc and tcc.

Upvotes: 5

Views: 1151

Answers (4)

J.P. Tosoni
J.P. Tosoni

Reputation: 574

I found this link which is slightly newer than the accepted answer: https://patchwork.ozlabs.org/project/gcc/patch/[email protected]/

Apparently up to 8.1.0. Not sure it is complete though.

Upvotes: 1

Havoc P
Havoc P

Reputation: 8467

For a lot of the useful ones you can copy the gcc version tests from glib's gmacros.h: http://git.gnome.org/browse/glib/tree/glib/gmacros.h

Depending on your project you may also be able to just use GLib, and then use G_GNUC_NORETURN or whatever instead of the __attribute__ directly.

It probably would be better in principle to do HAVE_GCC_ATTRIBUTE_NORETURN as Juliano suggests, but it may also be YAGNI work, depending on your project.

Upvotes: 2

Juliano
Juliano

Reputation: 41367

Do yourself a favor and don't do that.

Perhaps your software has some pre-compilation configuration/setup phase (like the autoconf team... ugh! (shivers) or something more sane like CMake), use that.

Write small tests (autoconf macros) that check if the compiler accepts the __attribute__ you are interested in and if it works as expected. If successful, write a HAVE_GCC_ATTRIBUTE_XXX macro in a config.h file which is included from your source.

Then use that macro with #ifdef to test if you should put or not the attribute in the function, or perhaps if you should use another hack to emulate the lack of the attribute.

Upvotes: 0

Related Questions