While designing xc [1], I settled on two things that make dependencies less complex:
- I copied #import from ObjC as well as providing #include. #import is the ‘only ever include this once’, akin to ‘#pragma once’, but at the caller site
- I got rid of header files. If you want to define enums or types they go in the same file as the code. It’s surprising how useful this is, and it stops any drift between method signatures in the header/code, because there’s no code…
The latter raised the question: what about library code ? So the compiler does double-duty with ‘#use <xxx>’. If xxx is a .xc file, it is the same as ‘#import <xxx>; use xxx’, where ‘use xxx’ brings any static class methods into the global namespace. If, however, xxx is a library name (without the lib prefix or .so/.a suffix), then the compiler reads the DWARF info in the library, and brings the methods/functions/types etc into the current-compilation-unit’s namespace. #use honours the -I and -L flags for search
So to use functions in ‘libtls.so’, an external C library, it’s just ‘#use <tls>’ and link with the library. Interop in other languages always annoyed me so making it simple was a goal.
spacedcowboy•32m ago
- I copied #import from ObjC as well as providing #include. #import is the ‘only ever include this once’, akin to ‘#pragma once’, but at the caller site
- I got rid of header files. If you want to define enums or types they go in the same file as the code. It’s surprising how useful this is, and it stops any drift between method signatures in the header/code, because there’s no code…
The latter raised the question: what about library code ? So the compiler does double-duty with ‘#use <xxx>’. If xxx is a .xc file, it is the same as ‘#import <xxx>; use xxx’, where ‘use xxx’ brings any static class methods into the global namespace. If, however, xxx is a library name (without the lib prefix or .so/.a suffix), then the compiler reads the DWARF info in the library, and brings the methods/functions/types etc into the current-compilation-unit’s namespace. #use honours the -I and -L flags for search
So to use functions in ‘libtls.so’, an external C library, it’s just ‘#use <tls>’ and link with the library. Interop in other languages always annoyed me so making it simple was a goal.
[1]: https://compile-xc.org/compiler/language/