这个c代码做了什么?
{
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}
Run Code Online (Sandbox Code Playgroud)
特别是我对subj感到困惑.
它是函数指针的强制转换.
该序列int (*)()用于获取不确定数量的参数的函数指针,并返回一个int.将它包含在括号中,例如(int (*)()),当与表达式结合时,将转换表达式的结果.
您提供的代码,注释:
// Declare a variable `func` which is a pointer to a function
int (*func)();
// Cast the result of the expression `code` and assign it to the variable `func`
func = (int (*)()) code;
// Use the variable `func` to call the code, cast the result to `int` (redundant)
// The returned value is also discarded
(int)(*func)();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1346 次 |
| 最近记录: |