Should every C or C++ file have an associated header file?

后端 未结 15 2218
情话喂你
情话喂你 2021-02-04 06:30

Should every .C or .cpp file should have a header (.h) file for it?

Suppose there are following C files :

  1. Main.C

  2. Func1.C

  3. <
15条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 07:17

    1. Header files are not mandatory.

    2. #include simply copy/paste whatever file included (including .c source files)

    3. Commonly used in real life projects are global header files like config.h and constants.h that contains commonly used information such as compile-time flags and project wide constants.

    4. A good design of a library API would be to expose an official interface with one set of header files and use an internal set of header files for implementation with all the details. This adds a nice extra layer of abstraction to a C library without adding unnecessary bloat.

    5. Use common sense. C/C++ is not really for the ones without it.

提交回复
热议问题