The following program prints the same number twice on gcc 4.8.2:
#include <stdio.h>
int main()
{
char a[13];
printf("sizeof a is %zu\n", sizeof a );
printf("sizeof(a) is %zu\n", sizeof(a));
}
According to this reddit post, gcc is not standard-conformant in this respect, because a parenthesized expression is not on the list of exceptions for when array-to-pointer decay does not happen.
Is this guy correct? Here is the relevant standard quote:
Except when it is the operand of the
sizeof
operator or the unary&
operator, or is a character string literal used to initialize an array of character type, or is a wide string literal used to initialize an array with element type compatible withwchar_t
, an lvalue that has type 'array of type' is converted to an expression that has type 'pointer to type' that points to the initial member of the array object and is not an lvalue.
Just to be clear, he argues that (a)
should trigger array-to-pointer decay, because parentheses are not covered in the list above (sizeof
operator, unary &
operator, string literal as initializer).