Skip to content

Add required headers to implementation section#3

Open
m4c0 wants to merge 2 commits intotsoding:masterfrom
m4c0:master
Open

Add required headers to implementation section#3
m4c0 wants to merge 2 commits intotsoding:masterfrom
m4c0:master

Conversation

@m4c0
Copy link
Contributor

@m4c0 m4c0 commented Apr 15, 2024

I was trying to use minirent in a niche gaming platform (sometimes called Windows) and it failed to build on its own if I had a file containing only these lines:

#define MINIRENT_IMPLEMENTATION
#include <minirent.h>

It required some common C library functions like assert, calloc and snprintf. Since they are not required in non-Windows platforms, I presume it is ok to add the required includes to the implementation block.

I also tweaked the example to move the minirent header to the top of the ls example, acting both as a "test" for the implementation block compilation, and to show future users that minirent is self-contained.

m4c0 and others added 2 commits March 29, 2024 10:49
This commit fixes the build of minirent if included by itself in a unit
file containing only its implemention.

```
 #define MINIRENT_IMPLEMENTATION
 #include "minirent.h"
```

Without this fix, there are compilation errors for `assert`, `calloc`
and `snprintf`.
This uses the example (and GitHub Actions) as a "unit test" to confirm
the header compiles on its own, without implicitly requiring its input
unit to import anything else.
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