On 11/28/18 6:04 AM, Florian Weimer wrote:
* Martin Sebor:
At the same time, the following passes on x86_64:
__attribute__ ((aligned (1))) void f1 (void) { }
_Static_assert (__alignof__ (f1) == 1); // wrong alignof result
__attribute__ ((aligned)) void f0 (void) { }
_Static_assert (__alignof__ (f0) == 16);
__attribute__ ((aligned (2))) void f2 (void) { }
_Static_assert (__alignof__ (f2) == 2);
Is there any value in implementing alignof on functions?
sizeof (f1) is defined to be 1, allegedly to support function pointer
arithmetic (which is why sizeof (void) is 1 as well). In practice, this
is confusing to the programmer because the size of a function is at
least known to the linker.
I also don't see any utility in applying sizeof to functions, at
least not with the existing semantics of evaluating to 1. alignof
seems somewhat more useful, but not tremendously so, for similar
reasons (at least it gives the lower bound). But both have been
implemented for ages so they couldn't be removed without some risk.
I don't know if the benefits of the removal would justify the risks.
Martin