4 ms·
I just want C/C++ to support `include source` statement. So in order to include some library I'll put #include source "libpng/png.c"; in my main.c file. A
by c-smile 8y ago
I just want C/C++ to support `include source` statement.
So in order to include some library I'll put
#include source "libpng/png.c";
in my main.c file. And that png.c may look as:
#include source "png-a.c"
#include source "png-b.c"
#ifdef PNG_FEATURE_C
#include source "png-b.c"
#endif
...
And that would be it.
C/C++ preprocessor is enough for configuration.
- MereInterest 8y agoCould you verify what you mean by an include source statement? As you describe its usage, it seems identical to the already existing #include statement, which does a text inclusion of another file.
- c-smile 8y ago#include "path.c"; inserts path.c into current compilation unit. #include source "path.c"; compiles and includes path.c as a new compilation unit ( https://en.wikipedia.org/wiki/Single_Compilation_Unit https://en.wikipedia.org/wiki/Single_Compilation_Unit ) . So if a-file.c and b-file.c are both have static int foo = 42; then these two files can be successfully included as #include source "a-file.c" #include source "b-file.c" But this: #include "a-file.c" #include "b-file.c" will produce the error "foo is already defined" This small feature will allow 99% of existing libraries to be included this way - without any makefile, GUP, GIP and the rest of the zoo. Now I can put in Microsoft VC++ this #pragma comment(lib, "some.lib") to include the library into final binary. #include source is just a generalization of the idea.
- fwip 8y agoAnd if b-file.c says "static int foo = 43;" what is the desired behavior?
- ghthor 8y agoI'd imagine a compiler error that static values, aka globals, must not differ at compile time. This would likely apply to consts as well.
- c-smile 8y ago"must not differ at compile time" not so, static declaration are local for the compilation unit so you may have as many different foo's as files you have in your project.
- c-smile 8y agoIn C/C++ static declarations are local to the compilation unit. So you will have two separate storages for foo - these will be two independent variables. That's how C and C++ work. And if you will have this (no static): int foo = 45; then linker will complain - "multiple 'foo' entities" as non-static entities have global visibility.
- jackewiehose 8y agoI think what we all want is a proper import-statement. > as a new compilation unit ( https://en.wikipedia.org/wiki/Single_Compilation_Unit https://en.wikipedia.org/wiki/Single_Compilation_Unit ) > Single Compilation Unit (SCU) is a computer programming technique [...] The technique can be applied to an entire program or to some subset of source files; when applied to an entire program, it is also known as a unity build. Who came up with that? I would say this "technique" doesn't even justify having a wikipedia page. In modern c++ you can be glad if you have a c++ unit that doesn't need to recompile on change because of all the header-only stuff. No one would include .cpp-files by choice.