Comment by gabrielsroka
2 days ago
1. You should add a URL when you you create a post on HN. You can indent code two spaces on HN, eg:
Stack s;
stack_init(&s);
dict_init();
exec(&s, "10 20 + ."); // Prints "30"
exec(&s, "1 2 3 4 .s"); // Shows stack contents
2. Your readme mentions a repl but I don't see it in the source code.
3. I'm not an expert in C but I thought header files shouldn't have code in them. The code should be in a .c file
4. Maybe move the code from USAGE into its own .c file.
#include "stacklib.h"
int main() {
Stack s;
stack_init(&s);
dict_init();
exec(&s, "10 20 + .");
printf("\n");
return 0;
}
technically, "header only libraries" can be exceptions to C code not being in header files. See STB as an example https://github.com/nothings/stb. The advantage theoretically is that you can #include this library and use its code and types from just one file, its a decent model IMHO, but it can be jarring to someone unfamiliar with header only libraries.
They have plenty of downsides and only one very minor advantage: You need to copy only a single file instead of two into your source. I am still puzzled why anybody could think this is a good idea...
And you also can name your single file to be included .c instead of "hiding the truth".
You can include a .c file just fine.