Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do people add their own folder to the standard include path?

When looking at different interesting projects over at GitHub, I came across the following file:

https://github.com/charliesome/slash/blob/master/src/lib/regexp.c

It seems like he includes his own files the same way as standard headers:

#include <slash/lib/regexp.h>

Instead of this way:

#include "slash/lib/regexp.h"

I guess he changes the include path to make this possible, but my question is: why? Isn't the quote syntax made for situations like this (including your own header file)?

like image 604
user2827100 Avatar asked Nov 11 '22 21:11

user2827100


1 Answers

For projects of moderate size and in particular installable ones, it's often more convenient to store headers in a separate directory like include/ under the project root instead of next to the C files.

After adding this directory to the include path, the choice of <> or "" becomes a stylistic one -- "" is only necessary for relative paths or if you add include directories via -iquote instead of -I, which is not particulary common.

An argument for using "" would be to explicitly mark headers as project-specific.

An argument for using <> would be that header inclusion will look the same in user and library code.

like image 98
Christoph Avatar answered Nov 14 '22 23:11

Christoph