Live data from Hacker News

Embedding Binary Objects in C

flak.tedunangst.com

131–140 of 141 posts

Re: Embedding Binary Objects in C

#131

Earlier quoted context omitted.

C does not have the feature (yet), it is not about being difficult or not.

The fact that C doesn't have the feature makes it difficult if I want to perform that task!

Seems like a trivial feature to add though.

Like all the other features C has been missing for the last 30 years.

Re: Embedding Binary Objects in C

#132
post #130
post #107

Earlier quoted context omitted.

In the section on search paths… It follows the same implementation experience guidelines as #include by leaving the search paths implementation defined, with the understand that implementations are not monsters and will generally provide… Really? We are going to "understand that implementations are not monsters" after what they've done with "undefined"? I think maybe these standards should be written from the perspec…

May I ask what's wrong with using xxd? I don't have an opinion about C, but C++ is already pretty complicated, and adding features to the language when there are already well-known solutions doesn't seem wise. (For the record, I'm aware that there are size limitation when using xxd, but there are also other solutions).

[deleted]

Re: Embedding Binary Objects in C

#133
post #27

Earlier quoted context omitted.

if you do that you could also do base64 ;)

But you can’t? Base64 won’t be recognized by the C compiler, you’ll end up having to decode it at runtime.

yep. That's a small piece of c-code you need to invest. See https://stackoverflow.com/questions/342409/how-do-i-base64-e...

Re: Embedding Binary Objects in C

#134
post #120

Earlier quoted context omitted.

You can sort the array during program initialization, if you care about the order.

It's probably already in link order. If you have to know the names of the symbols in code to be able to sort them, it sort of defeats the purpose of the scheme in the first place.

You might want to sort them by some other criteria.

For example, the FreeBSD kernel's use of this construct embeds a well-defined priority[1], and the array is sorted by this priority value at boot time.[2]

[1]: https://github.com/freebsd/freebsd/blob/master/sys/sys/kerne...

[2]: https://github.com/freebsd/freebsd/blob/master/sys/kern/init...

Re: Embedding Binary Objects in C

#136

Earlier quoted context omitted.

C does not have the feature (yet), it is not about being difficult or not.

The fact that C doesn't have the feature makes it difficult if I want to perform that task!

Thing is, embedding binary files is not that useful, and there are easy enough ways to do it for those few that really needed it.

The C standard has been very cautious about adding features that would make the standard and the compilers more complex since it is the lingua franca of computing.

Nowadays there is really just a handful of archs in use and their compilers are all backends for GCC/LLVM, so they are relaxing a bit the gating of features.

Re: Embedding Binary Objects in C

#137
post #130
post #107

Earlier quoted context omitted.

In the section on search paths… It follows the same implementation experience guidelines as #include by leaving the search paths implementation defined, with the understand that implementations are not monsters and will generally provide… Really? We are going to "understand that implementations are not monsters" after what they've done with "undefined"? I think maybe these standards should be written from the perspec…

May I ask what's wrong with using xxd? I don't have an opinion about C, but C++ is already pretty complicated, and adding features to the language when there are already well-known solutions doesn't seem wise. (For the record, I'm aware that there are size limitation when using xxd, but there are also other solutions).

Windows doesn't ship it, so now your build system got even more complicated on Windows.

Re: Embedding Binary Objects in C

#138
post #133

Earlier quoted context omitted.

But you can’t? Base64 won’t be recognized by the C compiler, you’ll end up having to decode it at runtime.

yep. That's a small piece of c-code you need to invest. See https://stackoverflow.com/questions/342409/how-do-i-base64-e...

So, by encoding in base64, you’ve made a more complicated solution which is also slower and harder to use? This seems like it is worse in every conceivable way. The only reason I can see for embedding base64 is if you need the source code to be compact, which makes sense for e.g. JavaScript but makes no sense for C.

I’ll take the simple, fast, and easy solution, thank you.

Re: Embedding Binary Objects in C

#140
post #130

Earlier quoted context omitted.

May I ask what's wrong with using xxd? I don't have an opinion about C, but C++ is already pretty complicated, and adding features to the language when there are already well-known solutions doesn't seem wise. (For the record, I'm aware that there are size limitation when using xxd, but there are also other solutions).

Windows doesn't ship it, so now your build system got even more complicated on Windows.

That's true, but I put that in the bucket of "C++ needs a package manager so that we can use dependencies more complicated than a single header file".
Post reply on HN