c - Do parentheses make a difference when determining the size of an array? -


the following program prints same number twice on gcc 4.8.2:

#include <stdio.h>  int main() {     char a[13];     printf("sizeof  %zu\n", sizeof );     printf("sizeof(a) %zu\n", sizeof(a)); } 

according this reddit post, gcc not standard-conformant in respect, because parenthesized expression not on list of exceptions when array-to-pointer decay not happen.

is guy correct? here relevant standard quote:

except when operand of sizeof operator or unary & operator, or character string literal used initialize array of character type, or wide string literal used initialize array element type compatible wchar_t, lvalue has type 'array of type' converted expression has type 'pointer type' points initial member of array object , not lvalue.

just clear, argues (a) should trigger array-to-pointer decay, because parentheses not covered in list above (sizeof operator, unary & operator, string literal initializer).

whether seemingly redundant parentheses affect semantics of program long-standing issue in c standard still hasn't been adequately resolved.

it commonly claimed ((void*)0) technically not null pointer constant, because there no rule says parenthesised null pointer constant null pointer constant.

some compilers issue error char s[] = ("abc");, because while character array can initialised string literal, rule doesn't cover parenthesised string literals.

there many similar examples. you've found 1 of them.

from can tell, concensus rule should c++ does, c never formally adopted. c++ makes parenthesised expression functionally equivalent non-parenthesised expression, few explicitly-stated exceptions. cover issues @ once.

so technically, guy considered correct, it's overly strict interpretation of standard nobody follows, since it's common knowledge standard faulty here.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -