cmake-init icon indicating copy to clipboard operation
cmake-init copied to clipboard

`#include ""` vs `#include <>`

Open friendlyanon opened this issue 4 years ago • 1 comments

#include <> will always look in directories the specified for the target or the system location(s), while #include "" will also look on the filesystem relative to the file before that.

This extra work incurs some cost, however the ability to group includes differently using clang-format is useful.

friendlyanon avatar Dec 17 '21 14:12 friendlyanon

#include <> will always look in directories the specified for the target or the system location(s), while #include "" will also look on the filesystem relative to the file before that.

Not quite

For <...>:

15.3.2

A preprocessing directive of the form

# include < h-char-sequence > new-line

searches a sequence of implementation-defined places for...

And for "...":

15.3.3

A preprocessing directive of the form

# include " q-char-sequence " new-line

causes... [skip] ...searched for in an implementation-defined manner.

The only thing here that isn't implementation defined as such is that, if the implementation declines to implement 15.3.3, it is allowed to replace the quotation marks with angle brackets and just do a 15.3.2 search instead.

Which all really just goes to say: It really is up to the individual project what kind of #include style will work for their specific setup, so: Whether or not cmake-init advertises that it is opinionated, for this specific purpose, there is such a thing as a wrong opinion, and the wrong opinion is per-project, meaning it cannot be known ahead of time.

SRNissen avatar Dec 03 '23 12:12 SRNissen