简体   繁体   中英

C - Casting char array to an integer pointer?

I have the following source code and there is one line, which i cannot understand the casting is been made. Can anyone explain please? I know the casting to an integer pointer (int *) but this is different. I cannot understand what the final line does. Is it returning an integer pointer? or i am wrong?

const unsigned char sc[] =  {  0x01, 0x01, 0x01, 0x01   };
return ((int (*)(void))sc)();

(int (*)(void))sc takes address of an array sc and converts it to a pointer to function which returns int .

() at the end then calls this function, and return value of this function (type int ) is again returned.

Weird part is that it seems as if the intention was to call function at address 0x01010101 , but it uses the address of array sc instead, which may be an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM