Skip to content

library writers should include their own headers as users of their library would #1609

Closed
@apenn-msft

Description

@apenn-msft

Edit:
This is a follow up from a comment on e47463c

Where library writers are including their own headers, they should prefer to do so the same way they would expect their users to. So for example, if you are creating foo.h and bar.h as part of some_lib, even though you could include bar.h locally as #include "bar.h" your users will not have bar.h at this local path. Instead, if you would expect your users to consume foo.h as "#include <author/library/foo.h>" then from foo.h, you should include bar.h as "#include <author/library/bar.h>"

Taking this guidance (that we should add to the GSL) combined with my PR to SF.12 this then translates succinctly to "if you're writing a library, you must use the angle-bracket form" because it encapsulates that if you're using the <> form it implies you are not including via the local relative path. From the original post:

If you're writing a library, you must use the angle-bracket form:

// inside mine/mine.h
#include <mine/detail.h>

This line will work no matter whether mine/mine.h is located in ~/sourcetree/src/ or in /usr/include — basically, if anybody ever includes this file via #include <mine/mine.h>, then we automatically know that the exact same include-search-path will be able to find <mine/detail.h>. On the other hand, doing #include "detail.h" might or might not work (depending on compiler options that ought to be irrelevant to us as library writers).

Originally posted by @Quuxplusone in #1596 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions