Are prototypes required for all functions in C89, C90 or C99?

前端 未结 6 1117
死守一世寂寞
死守一世寂寞 2020-11-22 16:55

To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit?<

6条回答
  •  不要未来只要你来
    2020-11-22 17:09

    A nice tip when writing new functions is to write them upside-down with main at the bottom so when you change your mind about the function's args or return type you don't have to fix the prototype too. Constantly fixing prototypes, and dealing with all the compiler's warnings when they are out of date gets really tedious.

    Once you have your functions working smoothly together move the code to a well-named module and put the prototypes in a .h file of the same name. It saves serious time. The biggest productivity aid I've found in 5 years.

提交回复
热议问题