旧代码:访问作为参数传递给另一个函数的函数的参数?
我必须维护一段旧代码,该代码在 64k 机器上编译时不再正常工作。
我有一个函数“solve”调用另一个函数“funct”作为指针传递:
intsolve(double*x,double xA,double xB,double zeps,double funct(double x,double*),... )
因此,“solve”可以与不同的可能函数一起使用,例如:
double isDgood(double D,double*Y);
在函数“solve”中,可以调用函数“funct”并使用以下方式访问其参数:
fA=funct(xA,(double*)(&funct+1));"
虽然我不熟悉这种语法,但我猜测开发人员假设未指定的参数只是被推入堆栈中。但是,该代码在 64k 平台上不再起作用。我应该如何更正该代码?
非常感谢您的帮助。
I have to maintain an old piece of code which does not work correctly anymore when compiled on 64k machines.
I have a function "solve" calling another function "funct" passed as a pointer:
int solve(double*x,double xA,double xB,double zeps,double funct(double x,double*),...)
Therefore, "solve" can be used with different possible functions as for example :
double isDgood(double D,double*Y);
From within the function "solve", it was possible to call the function "funct" and access its arguments using:
fA=funct(xA,(double*)(&funct+1));"
Although I am not familiar with this syntax, I guess that the developer was assuming that the unspecified arguments were just pushed in the stack. However, this code does not work anymore on 64k platforms. How can I correct this code? Should I specifically use Va_list?
Thanks you very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可怕的未定义行为。如果您想访问参数,则必须传递它们。
That's horrifically undefined behaviour. If you want to access the argument, you will have to pass them around.