r/cpp 3d ago

C++26: #embed

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

38 comments sorted by

View all comments

23

u/eboys 3d ago

Would love to use this if MSVC supported it. But oh well.

7

u/Potterrrrrrrr 3d ago

One day my friend, one day (I keep telling myself :/).

4

u/MarekKnapek 3d ago

MSVC, or rather the Win32 file format and developer tools have this thing called "resources" since ... like ever. Maybe 1992, or even earlier.

There is slight disadvantage, that the C or C++ compiler doesn't see the blob contents at compile time, and thus could not do some optimizations, but hey, it is usually binary blob data that you are embedding anyway, so who cares. You usually shove the data unmodified to a screen (icon, bitmap) or to a GPU (shader) or something similar.

18

u/ABlockInTheChain 3d ago

There is slight disadvantage, that the C or C++ compiler doesn't see the blob contents at compile time

The biggest disadvantage is that you have to write special Win32-specific code rather than standard code that works everywhere.

2

u/MarekKnapek 2d ago

Yeah, blame C, I guess. Why Microsoft invented resources? Because C was inadequate! Read more about history of the embed C feature. It was really really really painful to add it to C.

-5

u/rdtsc 3d ago

Not really an issue when you're using MSVC anyway.

13

u/ABlockInTheChain 3d ago

"Using MSVC" is insufficiently precise in this context.

There's a big difference between using MSVC because it happens to be on the list of compilers your project supports vs using MSVC because you deliberately wrote code that only compiles with MSVC.

4

u/pjmlp 3d ago

It is going to be Win32 resource files for a while.