dunck
dunck

Reputation: 398

Does function prototyping impact performance?

I'm curious as to, aside from maintainability, there are any real advantages of function prototyping. At this stage I can only se that it is useful for reading the program but can not find information as to whether the execution is affected because of prototyping.

Upvotes: 0

Views: 601

Answers (4)

ncmathsadist
ncmathsadist

Reputation: 4889

Function prototyping causes the compiler to flag improper calls to a function. Yes, "machine" efficiency is unaffected. On the other hand, programmer productivity might gain from knowing the potential source of a problem.

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726939

Having a prototype vs. a definition ahead of the point of call makes no difference in generated code.

Prototypes are necessary for the compiler to make proper conversions at the point of call. Once the compiler has finished, the fact that there was a prototype makes no difference.

Upvotes: 1

Dan Chase
Dan Chase

Reputation: 1042

DVDT,

Prototyping is very useful when separating your code into separate files. Additionally, to use function libraries in your program you'll usually need to create prototypes for the functions in the libraries. Lastly, some compilers read top-down, so a prototype must be included at the top of the file to enable functions that otherwise appear in the wrong order, to work. (not "Wrong" really, just in a different order for that particular instance). I've also been liberal with my definitions in this answer.

Strictly speaking though, these mechanisms are all part of "execution".

Upvotes: 0

R Sahu
R Sahu

Reputation: 206717

Does function prototyping impact performance?

Not at all. Function prototypes only define interfaces. They are not executable code. Executable code lies in implementations of those interfaces.

Upvotes: 2

Related Questions