logological / gpp

GPP, a generic preprocessor
https://logological.org/gpp
GNU Lesser General Public License v3.0
197 stars 31 forks source link

Order in which Directories are Searched Should Change, depending on Delimiter Used #27

Open duncanmac99 opened 6 years ago

duncanmac99 commented 6 years ago

The manual pages for the GNU C pre-processor state, as (apparently) does the POSIX standard, that using a '#include ' will cause each of the directories named in '-I' arguments to be searched, then the system directory/ies to be searched; no mention is made of the current file's directory. However, when the line ' #include "file" ' is used, the current file's directory is searched first, ^then^ the directories named in '-I' arguments are searched; no mention is made of the system directory/ies.

If a file named by #include and in the current directory happens to have the same name as a file in the system directories (or, worse, in a directory named in the '-I' list), then '#include ' will wind up picking up the wrong file. As the code now stands, the current directory is always checked first, without regard to which delimiter is being used. Using the argument '--curdirinclast' can fix that, but only at the cost of ruining it for the other #include statements (of the form ' #include "file" '); the latter statement then runs the risk of getting the wrong file instead, from somewhere other than the current directory.

The best work-around is to ensure that each and every file-name is unique. But, for unrelated reasons, this may be very hard if not impossible to do.