//lib2.zig
// #define DISABLE_THING will disable thing in lib1 but also
// will disable thing in lib2 which I need(because it looks on what is inside lib1)
// And yes it is actually safe... Just a bad design of two libs
#include <lib1.h>
#include <lib2.h>
I don’t need lib2 in all the places but it is just an autocomplete issue
Well, I would like to do it but lib2 actually looks to a thing which is conditionally defined inside lib1 so it is more something like:
//lib1.h
#ifndef DISABLE_THING
#define THING_AVAILABLE
void thing() {...}
#endif
//lib2.h
#ifdef THING_AVAILABLE
void some_func() { // The only thing from lib2 I need at all :)
thing();
}
#endif
And so I need both versions of lib1 both with disabled and enabled thing. So I yeah, inherited from C dependency hell…
It is a noname extension to a noname “engine” on SDL2 written in very strange state of mind. Like if there is no THING feature in original lib why to even define function used only with a THING? Which is great idea but awfully implemented…
That func in lib2 generally gives you almost static list of requirements (which you than need to check). Nothing special and it doesn’t depend much on anything except on data returned from lib1 (which in turn also very self-containing). So it would be safe to use the func from lib1 even with disabled lib1 (except it is all just not defined than…)
Slightly related, but I wished that more languages would offer optional structural typing, e.g. an annotation on struct declarations that makes two independently defined structs with different names but with the same ‘interior layout’ assignable to each other without an explicit cast.