有没有在C不使用的函数原型什么好处? [英] Are there any benefits to NOT using function prototypes in C?

查看:185
本文介绍了有没有在C不使用的函数原型什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和一些C code不包含函数原型为某一类功能工作。是否有任何优势,不使用函数原型?这些功能从来没有称呼对方,并没有参数。在code变化很大,所以也许它只是一条线少编辑?

I'm working with some C code that does not contain function prototypes for a certain class of functions. Are there any advantages to not using function prototypes? The functions never call each other and have no parameters. The code changes a lot, so maybe it's just one less line to edit?

推荐答案

函数原型外部函数。我的原则是,每一个非静态函数得到一个原型,除了主()。我用的是'-Wmissing的原型'GCC选项。通常它捕捉是,当我忘记声明一个函数静态的。

Function prototypes are for external functions. My rule is that every non-static function gets a prototype, except main(). I use the '-Wmissing-prototypes' GCC option. Usually what it catches is when I forget to declare a function static.

此外,这种方式声明函数在C:

Also, declare functions in C this way:

void function(void);

和不是这样的:

void function();

由于第二种方式意味着函数需要的参数数目不详,这是不是你想要的(它与pre-ANSI C兼容)。

Because the second way means that the function takes an unspecified number of parameters, which isn't what you want (it's for compatibility with pre-ANSI C).

这篇关于有没有在C不使用的函数原型什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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