Skip to content

Move _IMPLEMENTATION outside of _H - #282

Open
ysoftware wants to merge 1 commit into
memononen:masterfrom
ysoftware:master
Open

ysoftware wants to merge 1 commit into
memononen:masterfrom
ysoftware:master

Conversation

@ysoftware

Copy link
Copy Markdown

In my project multiple files want to include nanosvg.h.
I also like to add all #define *_IMPLEMENTATION at the end of main.c, just to keep things in one place.

My usage:

#include "example.h" // includes nanosvg.h

...

int main(void) { ... }

#define NANOSVG_IMPLEMENTATION
#include "nanosvg.h"

#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvgrast.h"

Currently this is not possible because if the implementation is not included the first time, it will never be included, since it's declared inside of NANOSVG_H guard. With the new change, you can do this.

One possible issue I see is that if the user declares NANOSVG_IMPLEMENTATION early, then all successive includes will produce an error (since implementation will keep getting added multiple times). I feel like this is good and should not be solved by the library, since it is not trying to hide information from the user and gives them proper understanding of what is going on. It is also easily solvable with an #undef. I don't insist on this decision though, if you disagree.

This allows the user to first include the header file in multiple places and only then add it with the implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant