Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
When a function is called,but we do not use function prototype,Please list of potential risks

[EDIT]
When using the function pointer, does it produce a deadlock, does it happen?
Posted
Updated 10-Apr-11 22:00pm
v2

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.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 11-Apr-11 4:02am    
I voted 5. But, there are exclusions, but even them the risk is not bigger than passing parameters not meeting pre-conditions. It's much worse with C (I would say, pretty bad in certain cituations) as CPallini correctly pointed out.
--SA
Sergey Alexandrovich Kryukov 11-Apr-11 4:10am    
Hans, I had to move OP's follow-up answer to Question, but that removed your comment on it (sorry), which is basically quite correct. I referenced your comment in my Answer, please see.
--SA
Hans Dietrich 11-Apr-11 4:15am    
OK, no problem.
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.


On the other hand

  • 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.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 11-Apr-11 4:02am    
This is more precise answer, my 5.
--SA
Albert Holguin 11-Apr-11 9:46am    
good answer... guess that's why default prototypes have gone away
Wendelius 11-Apr-11 13:47pm    
Good answer, my 5
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900