|
|
|
|
|
by duelingjello
2386 days ago
|
|
In a C compiler (cc command), there are only compilation units (.c -> .o). Headers (.h) were bolted-on (cpp command) to deduplicate interfaces (forward declarations). This header-only containing implementations adds its code to every compilation unit and the linker has to be smart enough to deduplicate identical symbols across many compilation units. Linkers (ld command) are provided either by the platform vendor or the compiler vendor, so they may or may not be able to do this. Binutils on Linux is able to do so IIRC. It's a terrible practice that promotes cowboy coding. It should just use two files, which would cause less problems in the real world. You can also write C without headers or newlines. IOCCC may welcome it but why would you ship it or encourage people to use it? |
|
That's not how this works. It's actually a pretty clever trick, and it effectively behaves as a .h / .c pair of files. See https://github.com/nothings/stb/blob/master/docs/stb_howto.t...