The difference between the C language function name and contact address and take

Sometimes we see the following code: 

/*****************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void test()
{
    printf("123456\n");
}

int main(int argc, char *argv[])
{
    printf("0x%x\n",test);
    printf("0x%x\n",&test);
}

[root@localhost pht]# ./a.out 
0x8048328
0x8048328

According to the original meaning of the & operator, which requires its operand is an object, but the function name is not an object (function is an object), originally & test was illegal, but a long time ago some compilers have been allowed to do so, 
c / c ++ standard makers for the development of the concept of the object has been the reason, but also acknowledged the legitimacy of & test. 

Therefore, for the test and & test you should be understood, test is the first address of the function, it is of type void (), & test represents an address of the function test the object points, 
it is of type void (*) (), and therefore test and & test address value represented is the same, but not the same type. test is a function, the value of the test expression & is a pointer! 


There are similar problems with this on an array of Natori address. 
A int [100]; 
the printf ( "% P \ n-", A); 
; the printf ( "% P \ n-", & A [0]) 

as the value of printing. 
However, the name of the array a, points to the array with 100 of type int; 
& A [0] points to the element a [0]. 
That is, they have the same value, but different types of points. 

Standard explain its rationale in this issue, are summarized as follows: 
6.5.3.2 Address and indirection Operators 
s Some Implementations have have not allowed at The & operator to BE AN Applied to Array or A function. 
(The construct was permitted in early versions of C, then later made optional.) The C89 Language 
Committee endorsed the construct since it is unambiguous, and since data abstraction is 
enhanced by allowing the important & operator to apply uniformly to any addressable entity. 

Guess you like

Origin www.cnblogs.com/still-smile/p/11592292.html