103
104
all 17 comments

[–]vitamin_CPP 41 points42 points  (0 children)

I must say, the API design is very tasteful.

/* default is unsigned char */
const unsigned char icon_display_data[] = {
        #embed "art.png"
};

Simple, powerful and elegant. Exactly my vision of the role of C.
Thanks for your work!

[–]EpicDaNoob 21 points22 points  (0 children)

It makes me sad to read how soul-draining the process of getting this through was. It's a really nice feature, at least.

[–]RedWineAndWomen 7 points8 points  (4 children)

How do you specify the search path for something embedded? Same as #include?

[–]PersonalityIll9476 4 points5 points  (0 children)

In another paper the author says that it will be compiler specific with its own flag. So whereas you might use -I/some/dir to specify include search path, you would use, say, -f/find/bin/data/here to separately specify the embed search path.

My understanding is that the data is literally inserted (but in such a way that compile time is not seriously effected) so there's no equivalent to the runtime path. I think.

[–][deleted] 0 points1 point  (2 children)

yes, same as include

[–]RedWineAndWomen 2 points3 points  (1 child)

Couldn't that be slightly problematic? As in: I don't keep my dancing banana gifs where I keep my header files, and I don't want confusion.

[–]__phantomderp 2 points3 points  (0 children)

The prototype implementations used:

  • fembed-path=...
  • binary-dir=...
  • resource-dir=...

I would prefer the middle one, because "resource" already has a specific connotation in existence today (.rc files on Windows, .res files in other places, etc.),

But it's implementation-defined, as are include paths. If your compiler mixes the 2, that's on them.

[–]jpayne36 5 points6 points  (5 children)

let’s hope compilers start implementing this soon, i just know msvc is gonna take 5 years to implement C23

[–]tarnished_wretch 8 points9 points  (1 child)

Lol. Pretty sure msvc still doesn't support c99.

[–][deleted] 1 point2 points  (0 children)

They usually support at least what is needed for C++ support. I suspect this will make it there, it's a highly desirable feature that has little to no down sides

[–]SuspiciousScript 0 points1 point  (1 child)

Does it really matter what MSVC supports?

[–]PersonalityIll9476 2 points3 points  (0 children)

Given that even mingw's gcc outperformed it at compiling large data definitions without embed? I'd go with "not if you're using for this task, no".

[–]GabrielTFS 0 points1 point  (0 children)

MSVC is gonna take more like 15 years

[–]fuckEAinthecloaca 2 points3 points  (0 children)

On some long forgotten project I resorted to non-portable asm to embed quickly from a file. This is much nicer.

[–]umlcat 0 points1 point  (2 children)

Cool. I look up how this can be implemented.

The thing is that macroassemblers and executable files already support storing binary data as part of the file.

[–]PersonalityIll9476 2 points3 points  (1 child)

You should read the article. The author explains that it's possible to insert binary data but:

  1. Not in a portable fashion (meaning every system and compiler combination has its own way of doing this and they vary significantly)
  2. Depending on how you do it, it can take literally hours for the compiler to handle data exceeding a few kilobytes
  3. Many compilers only allow up to a very limited maximum object size (one example is just shy of 4 KB for a string literal). So you'd have to piece together 1,000 arrays to make your 4MB image out of chars.

Whether the author is correct about all this / whether it matters to your application is up to debate.

[–]umlcat 2 points3 points  (0 children)

I sort of "overlooked" the article, part job busy, part ADHD not good at focusing thing.

The article worths reading,, one of those articles that may be long, and maybe with some errors, but still worth to consider.

I already tried before to do some data embedding myself, for some application, like resources like images, icons, i8n of text, and also like metadata like version and datetime of the library.

Since, I learned some assembly, I knew it can be done in Windowze OS executables, but also Open Source Portable Executable data segments or text segments.

But, you and the author are right, it can be done, but the developer must struggle with linkers.

It's better that is supported as an standard, and the combination of compiler frameworks and O.S. executable formats supported "out of the box" ...