混淆了函数调用pre-ANSI C的语法 [英] Confused over function call in pre-ANSI C syntax

查看:207
本文介绍了混淆了函数调用pre-ANSI C的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在处理一些pre-ANSI C的语法。见我有以下的函数调用在一个条件

I'm dealing with some pre-ANSI C syntax. See I have the following function call in one conditional

 BPNN *net;
 // Some more code
 double val;
 // Some more code, and then,
 if (evaluate_performance(net, &val, 0)) {

但随后的函数 evaluate_performance 定义如下(的有功能上述条件):

But then the function evaluate_performance was defined as follows (below the function which has the above-mentioned conditional):

evaluate_performance(net, err)
BPNN *net;
double *err;
{

为什么 evaluate_performance 用两个参数定义,但所谓的三个参数?什么是'0'是什么意思?

How come evaluate_performance was defined with two parameters but called with three arguments? What does the '0' mean?

和,顺便说一句,我是pretty确保它没有要求其他 evaluate_performance 别处定义;我有的grep ED通过所涉及的所有文件和我pretty确保我们应该谈论同样的 evaluate_performance 在这里。

And, by the way, I'm pretty sure that it isn't calling some other evaluate_performance defined elsewhere; I've greped through all the files involved and I'm pretty sure the we are supposed to be talking about the same evaluate_performance here.

谢谢!

推荐答案

如果你调用了没有声明原型(这里是这样)的函数,那么编译器假定它接受一个任意的数量和类型的参数,并返回 INT 。此外,字符参数都提升到 INT 取值和浮动,则晋升为双击 S(这些被称为的默认参数提升的)。

If you call a function that doesn't have a declared prototype (as is the case here), then the compiler assumes that it takes an arbitrary number and types of arguments and returns an int. Furthermore, char and short arguments are promoted to ints, and floats are promoted to doubles (these are called the default argument promotions).

这被认为是不好的做法,在新的C code,原因很明显 - 如果函数不返回 INT ,不良可以保证,你$ P从$检查您传递正确数量和类型的参数和参数可能会被错误地提升pvent编译器。

This is considered bad practice in new C code, for obvious reasons -- if the function doesn't return int, badness could ensure, you prevent the compiler from checking that you're passing the correct number and types of parameters, and arguments might get promoted incorrectly.

C99,C标准的最新版本,将删除语言此功能,但在实践中许多编译器在C99模式下工作时,对传统设备的兼容性还是让他们甚至

C99, the latest edition of the C standard, removes this feature from the language, but in practice many compilers still allow them even when operating in C99 mode, for legacy compatibility.

至于多余的参数,他们在技术上的未定义行为根据C89标准。但在实践中,他们通常只是被运行时忽略。

As for the extra parameters, they are technically undefined behavior according to the C89 standard. But in practice, they will typically just be ignored by the runtime.

这篇关于混淆了函数调用pre-ANSI C的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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