是什么`((无效(*)())为0x1000)();'是什么意思? [英] What does `((void (*)())0x1000)();` mean?

查看:914
本文介绍了是什么`((无效(*)())为0x1000)();'是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个code,它的目的是设定程序计数器跳转到地址 0×1000 。我知道它做什么,但我不明白。它关系到我缺乏的C语言知识。可能是你能赐教。下面是声明/功能(我甚至不知道它是什么:))

Here is a code that purpose is to set the program counter to jump to address 0x1000. I know what it does but I don't understand how. It is related to my lack of C language knowledge. May be you can enlighten me. Here is the statement/function (I even don't know what it is :))

((void (*)())0x1000)();

我的事情是指针,返回无效和不接受任何参数的函数。如果我错了,请大家指正。

I thing it is pointer to a functions that returns void and accepts no argument. Please correct me if I am wrong.

推荐答案

C 声明是由内德$ C $光盘拿出来用一个简单的规则:从标识符开始和右侧检查 [] (阵列)或()(功能),然后检查左侧为值(存储阵列中或由函数返回),不越位括号的类型;从括号逃脱,并重复。

C declarations are decoded from inside out using a simple rule: start from the identifier and check on the right side for [] (array) or () (function) then check on the left side for the type of the values (stored in the array or returned by the function), without crossing the parentheses; escape from the parentheses and repeat.

例如:

void (*p)()

P 是(右侧无)的指针的(在左边,不要过括号中)的的(逃避括号,看了下一级)的函数的(右)的不返回任何内容的(左)。

p is (nothing on the right) a pointer (on the left, don't cross the parentheses) to (escape the parentheses, read the next level) a function (right) that returns nothing (left).

在剩下的标识符( P 在这种情况下)丢失,都是一个类型声明。

When the identifier (p in this case) is missing, all that remains is a type declaration.

括号括起A型,把一个价值面前的是一个类型转换。

A type enclosed in parentheses, put in front of a value is a type cast.

(void (*)())0x1000

转换次数 0×1000 指针,不会对该款返回任何的(见什么是括号外的函数 p 的声明之上)。

converts the number 0x1000 to a pointer to a function that doesn't return anything (see what's outside the parentheses in the paragraph about the declaration of p above).

在下一级别,前pression上述(一个指针指向一个功能可以以相同的方式作为函数名中使用)被用于执行code对准

On the next level, the expression above (a pointer to a function can be used in the same way as a function name) is used to execute the code pointed at.

请参见下面的整个前pression去组成:

See below the entire expression de-composed:

(
  (
    void (*)()   /* type: pointer to function that doesn't return anything     */
  )0x1000        /* value 0x1000 treated as a value of the type declared above */
)                /* enclose in parentheses to specify the order of evaluation  */ 
();              /* the pointer above used as a function name to run the code  */

这篇关于是什么`((无效(*)())为0x1000)();'是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆