如何检查头文件的有效性C编程语言 [英] How to check validity of header file in C programming language

查看:262
本文介绍了如何检查头文件的有效性C编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有C语言编程的方式来检查,如果从头文件中的函数原型对应于编译时实际的函数定义。
例如,如果我做的头文件,然后更改在头文件中所描述的一些功能的签名,我可以在编译时检查是否存在错误的原型在头文件?是编译器或编译之前的一些其他工具的工作吗?
谢谢你。

Is there a way in C programming language to check if function prototypes from a header files corresponds to actual function definition in compile time. For example, if I made header file, and then change signature of some function described in that header file, can I check in compile time if there is a wrong prototype in header file? Is that a job of the compiler or some other tool before compilation? Thanks.

推荐答案

如果您有两个不同的原型声明相同的函数名,编译器应该抓住这个,即:

If you declare the same function name with two different prototypes, the compiler should catch this, i.e.:

int foo(int a, int b);

...

int foo(int a, float b) { ... }

当然,如果你真的重命名功能,那么编译器不能抓住它,即:

Of course, if you actually rename the function, then the compiler cannot catch it, i.e.:

int foo(int a, int b);

...

int fee(int a, int b) { ... }

当然,除非你试图从其他地方打电话。然后,连接器会抱怨。

Unless, of course, you attempt to call foo from elsewhere. Then the linker will complain.

这篇关于如何检查头文件的有效性C编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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