What is the significance of forward declaration in C programming?

后端 未结 4 1811
长情又很酷
长情又很酷 2021-01-04 18:57

I am now learning C programming through Learn C the Hard Way by Zed A. Shaw. There is this code (taking from his website):

#include 
#include          


        
4条回答
  •  礼貌的吻别
    2021-01-04 19:48

    You should declare functions in the order that makes sense. This should be described in the coding style document you follow. One example of common design is:

    • h-file with all publically available function declarations.
    • c-file with all private function declarations at the top.
    • then in the same c-file follows the function definition of the public functions.
    • and then at the end of that c-file, the function definition of the private functions.

    In addition to style and design concerns, ancient versions of C would start to "make up" function parameters and return types if there was no prototype at all visible before the function call.

提交回复
热议问题