What type is a function name in C? [duplicate]

What type is a function name in C?

A function name or function designator has a function type. When it is used in an expression, except when it is the operand of sizeof or & operator, it is converted from type “function returning type” to type “pointer to a function returning type”. (This is specified in C99, 6.3.2.1p4).

Now

sizeof(func)

is not valid C as sizeof is not allowed with an operand of function type. This is specified in the constraints of the sizeof operator:

(C99, 6.5.3.4p1 Constraints) “The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member.”

But

sizeof(func)

is allowed in GNU C.

There is a GNU extension in GNU C that allows it and in GNU C sizeof with an operand of function type yields 1:

6.23 Arithmetic on void- and Function-Pointers

[…] sizeof is also allowed on void and on function types, and returns 1.

http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)