Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C指针算法在机器代码测试仪中的应用_C_Pointer Arithmetic - Fatal编程技术网

C指针算法在机器代码测试仪中的应用

C指针算法在机器代码测试仪中的应用,c,pointer-arithmetic,C,Pointer Arithmetic,我在网上发现了一个类似的机器代码测试程序,它是用C编写的 测试仪使用指针算法运行机器代码缓冲区 #include <stdio.h> #include <string.h> unsigned char code[] = \ "machine code to be executed"; void main() { int (*ret)() = (int(*)())code; ret(); } #包括 #包括 无符号字符代码[]=\ “待执行的机器代码”

我在网上发现了一个类似的机器代码测试程序,它是用C编写的

测试仪使用指针算法运行机器代码缓冲区

#include <stdio.h>
#include <string.h>

unsigned char code[] = \
"machine code to be executed";

void main() {
    int (*ret)() = (int(*)())code;
    ret();
}
#包括
#包括
无符号字符代码[]=\
“待执行的机器代码”;
void main(){
int(*ret)(=(int(*)()代码;
ret();
}
有人能解释这两种指针算法背后的逻辑吗 上面的台词

有人能解释一下上面两行指针算法背后的逻辑吗

没有指针算法。代码只是声明一个变量(
ret
),其类型是指向不带参数并返回
int
的函数的指针。它将该变量设置为指向
code
,该变量可能包含机器代码的实际字节,然后使用它进行函数调用

有人能解释一下上面两行指针算法背后的逻辑吗


没有指针算法。代码只是声明一个变量(
ret
),其类型是指向不带参数并返回
int
的函数的指针。它将该变量设置为指向
code
,该变量可能包含机器代码的实际字节,然后使用它进行函数调用。

这通过将指向对象的指针投射到函数指针来正式调用UB:“
int(*ret)(=(int(*)code;
”@alk停止此UB谬误。此类强制转换在标准中被明确列为“语言的通用扩展”,许多(大多数)平台都要求它是正确的。执行此指针是另一回事。它通过将指向对象的指针强制转换为函数指针来正式调用UB:“
int(*ret)(=(int(*)code;
”@alk停止此UB谬误。此类强制转换在标准中被明确列为“语言的通用扩展”,许多(大多数)平台都要求它是正确的。执行这个指针是另一回事。