gpp icon indicating copy to clipboard operation
gpp copied to clipboard

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

Open duncanmac99 opened this issue 6 years ago • 0 comments

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.

duncanmac99 avatar Sep 15 '18 21:09 duncanmac99