What is the significance of forward declaration in C programming?

后端 未结 4 1813
长情又很酷
长情又很酷 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:50

    Forward declarations of functions are unavoidable whenever your call graph is cyclic; that is, whenever you have (direct or indirect) recursion between functions.

    They are useful if you want to separate your program into more than one translation unit, as they allow separation of declaration and definition of functions (placing the declaration in a .h header and the definition in a .c file).

提交回复
热议问题