S
S
Sap_ru2018-06-06 11:40:15
C++ / C#
Sap_ru, 2018-06-06 11:40:15

Are headers in C/C++ separate folders or together with sources? Connect with paths or not? Systemic or regular?

Interested in opinions on the following questions:
1) Store headers together with their corresponding source files or in separate folders?
2) Connect headers with or without a path? Those. #include "my_header.hpp" with including a bunch of folders in the header search path or #include "some_path/my_header.hpp".
3) Whether to add project folders to the search path of system headers (to connect via #include <> ). I was surprised to notice that more and more projects indicate their header folders as system ones.
Not for a holivar, but for the sake of education. I have already had my own position on these issues for 20 years, which has changed at least three times during this time;) but I thought that maybe there are some new points that I missed.
My typical projects are mostly embedded where all the sources along with the libraries are in the same source tree. The percentage of code reuse between projects is quite large, but due to the iron specifics, it is often necessary to patch typical sources for a specific project.
Up to hundreds of files per typical project.
At the moment, headers are stored in folders with the corresponding source files, or in the root of the sub-trees of some subsystems of the program, so as not to look for which header from which file later. In the search path, only the root of the source texts and the roots of the source libraries are connected, i.e. all header paths are relative to the root.
Does it make sense to do otherwise?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sakhno, 2018-06-06
@Punk_Joker

I keep each software module in a separate folder. and the header lies next to the implementation. The project properties set the paths to all folders. This makes it possible to port modules without having to suddenly change the include paths if one module depends on another.

R
res2001, 2018-06-06
@res2001

1. They store headers in separate folders if it is a library and you need to give a certain set of headers to the end user. In this case, internal headers can lie (and lie) together with the source code.
2. and 3. it doesn't matter at all.
The organization of the project is the same as yours. Works fine. I see no reason to change anything in this regard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question