Why Prototypes?

The prototype tells the compiler what type of return value, if any, the function has, and it tells the compiler the number and type of function arguments.

Still, you might wonder, wht does the compiler need a prototype? Can't it just look further in the file and see how the functions are defined? One problem with that approach is that it is not very efficient. The compiler would have to put compiling main() on hold while serching the rest of the file. An even more serious problem is the face that the function might not even be in the file. C++ allows you to spread a program over several files, which you can compile in dependently and then combine later. The same is true if the funtion is part of a library.

Prototypinig takes place during compile time and is termed static type checking.

(from <C++ Primer Plus>)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章