gpt4 book ai didi

c - 为什么函数调用只传递第一个参数

转载 作者:行者123 更新时间:2023-11-30 18:33:36 25 4
gpt4 key购买 nike

我试图仅通过强制转换来调用函数(第 15 行),但只有第一个参数被传递,我该如何修复它?

我尝试将浮点值“2”更改为 2.0f 以声明它是浮点而不是 int,但它仍然不起作用。

!请注意,该代码很糟糕,因为它是 code golf ,第15行稍后必须是dll形式,这里的代码只是一个测试程序,以避免多次启动目标进程。这是我的实际代码,得分为 58 个字符

DllMain(a,b,c){((int(*)(int,float))927309216)(‭7903472‬,2);}
#include <Windows.h>
#include <stdio.h>
char * sSkelModelStencil = "SkelModelStencil"; //here I reproduce the char like it is in the memory

void SetConsoleFloat(const char *sKey, float fVal) //this is the reproduction of SetConsoleFloat in CShell.dll
{
printf("arg1: %s arg2: %f\n", sKey, fVal); //printing the arguments getting passed into the function
return;
}

int main()
{
while (1) {
SetConsoleFloat("SkelModelStencil", 2); //calling the reproduction function
((int(*)())SetConsoleFloat)(sSkelModelStencil,2); //calling the reproduction function via a cast & using SetConsoleFloat addr
system("PAUSE");
}
}

最佳答案

在某些架构中,参数的传递方式取决于它们的声明方式。例如,特殊寄存器可以用于float参数。重要的是函数类型的声明,而不是参数表达式的声明。

参数签名 ()(const char *sKey, float fVal) 不同,因此 fVal 参数为传递的方式与函数期望接收它的方式不同。

关于c - 为什么函数调用只传递第一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56433891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com