Should I put many functions into one file? Or, more or less, one function per file?

后端 未结 9 886
故里飘歌
故里飘歌 2021-01-02 02:54

I love to organize my code, so ideally I want one class per file or, when I have non-member functions, one function per file.

The reasons are:

  1. When

9条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 03:56

    For the header part, you should combine items into logical groupings and create your header files based on that. This seems and is very logical IMHO.

    For the source part, you should put each function implementation in a separate source file (static functions are exceptions in this case). This may not seem logical at first, but remember, a compiler knows about the functions, but a linker knows only about the .o and .obj files and its exported symbols. This may change the size of the output file considerably, and this is a very important issue for embedded systems.

    Checkout glibc or Visual C++ CRT source tree...

提交回复
热议问题