r/cpp • • Aug 06 '26

C++26: #embed

https://www.sandordargo.com/blog/2026/08/05/cpp26-embed
137 Upvotes

42 comments sorted by

View all comments

Show parent comment

1

u/Status_Force_7249 Oct 31 '26

If you keep them in a separate translation unit that wouldn't be much worse than a linker, but still technically worse. I tried so called linker magic once with gcc/make and it wasn't too difficult to figure out, and if it is difficult for any given linker or build system, then that's the place to work on to improve the ergonomics IMO, rather than pushing a niche feature into the language standard and then going out of your way to sell it as the ultimate solution.

GPU shaders, small embedded icons, or text templates - that's the exact use cases I'm talking about. I do want a rebuild, but I see no reason to compile any C++ for those changes, I'd have only the linker invoked. A use case where I would want the compiler would be something like a small lookup table that you'd do some arithmetic with and have the compiler optimize it for you (and it must be small to be optimized effectively, so all that talk of how fast megabytes are embedded is moot).

Again if you keep all opaque resource embeds in a separate translation unit that would be fine (not the best, just fine), but the way everyone's talking about #embed I have a feeling that's not what's going to happen. I see a lot of constexpr and no mention of extern, so following that line of thinking people will just embed everything in headers, and then all the code that refers to the aforementioned shader, icon or text will need to be recompiled every time those change.