Re: Use of __attribute__ in declaration and in definition of the function
NKurzman might be right that "optimize" is only needed for the definition. But for other attributes this is definitely not true. For example attributes "pure" and "const" are allowing optimization on the calling code and that is why I believe they need to be visible in the declaration. Same for format and format_arg, which enables compiler checks on the calling side.
I'm with du00000001 on the warnings and that's why I'm even compiling with "-Werror".
But for the function declaration and definition it is the safest to always keep it completely identical. The declaration is meant to represent the general properties of the function. Therefore, it makes sense to keep it identical to the definition. I think I once have even read about a case that it can be dangerous if some attributes are different or missing, but I don't remember the exact case anymore.
I think finding out what is needed and what is not doesn't work here, because there is absolutely no documentation about it, besides the User's Guide, which doesn't cover this topic at all. So, how are you supposed to find out what's relevant in a reliable way?