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

前端 未结 6 1120
死守一世寂寞
死守一世寂寞 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:13

    Yes, every function must have a prototype, but that prototype may appear either in a separate declaration or as part of the function's definition. Function definitions written in C89 and up naturally have prototypes, but if you write things in classic K&R style, thus:

    main (argc, argv)
    
      int argc;
      char **argv;
    
    {
      ...
    }
    

    then the function definition has no prototype. If you write ANSI C (C89) style, thus:

    main (int argc, char **argv) { ... }
    

    then the function definition has a prototype.

提交回复
热议问题