调用函数而不使用函数原型时会有什么风险 [英] what risk is When function is called and not use function prototypes

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

问题描述

调用函数时,但我们不使用函数原型,请列出潜在风险


When a function is called,but we do not use function prototype,Please list of potential risks


When using the function pointer, does it produce a deadlock, does it happen?

推荐答案

如果您在未先声明函数原型的情况下尝试调用函数,编译器将禁止.所以我会说风险为零,因为您将无法做到这一点.
If you try to call a function without first declaring its prototype, the compiler will barf. So I would say the risk is zero, because you''re not going to be able to do it.


C++C编译器的行为有所不同:

  • C++编译器不接受没有原型的函数(除非在调用它之前在同一个源文件中定义了该函数),因此Hans已经指出,这没有风险,因为您甚至都无法编译代码.
C++ and C compilers behaves differently:

  • The C++ compiler doesn''t accept a function without prototype (unless it is defined in the same source file, before the calling one), hence, has Hans already pointed out, there is no risk, because you can''t even compile the code.
  • C编译器在假定默认原型"的情况下接受该函数(它可能会生成警告消息,具体取决于选择的警告级别).
    现在,如果您幸运的话,默认原型"将适合实际的功能签名.如果您不走运,那么 编码上帝的Nemesys 会让您不胜其烦,结果不正确.
  • The C compiler accepts the function (it may generate a warning message, depending on selected warning level) assuming a ''default prototype''.
    Now, if you''re lucky, the ''default prototype'' will fit with the actual function signature. If you''re out of luck then the Coding God''s Nemesys will flame you with, at beast, incorrect results.


回答有关死锁的问题:

死锁和函数签名的问题没有共同之处.在任何情况下都不会考虑这些问题.汉斯回答说:这取决于函数的作用".

当两个或多个线程彼此等待时,死锁全部与线程有关.在这种情况下,也不例外,没有任何损坏或崩溃.这些线程只是无限地处于等待状态.您可能会说完全不同的东西,而您误将其称为死锁.

—SA
Answering a follow-up Question about deadlock:

Deadlocks and the problems of the function signature has nothing in common. There are no situations when those problems can be considered in any connection. Hans replied with something like: "this depends on what the function is doing".

Deadlocks are all about threads, when two or more threads wait for each other. In such cases, there are no exception, nothing is corrupting or crashing. Those thread are simply stay in wait state infinitely. You could mean something completely different which you called a deadlock by mistake.

—SA


这篇关于调用函数而不使用函数原型时会有什么风险的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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