Why Nostr? What is Njump?
2025-03-24 16:17:54

Red Rozenglass on Nostr: In other news, why did no one tell me about xxd -i before: -i | -include Output in C ...

In other news, why did no one tell me about xxd -i before:

-i | -include
Output in C include file style. A complete static array defini‐
tion is written (named after the input file), unless xxd reads
from stdin.
For example, you can add this to your build pipeline, to turn a string to an embedded array of characters. Just #include printf-template.html.h in your code. If printf-template.html contains printf control sequences, like %s, they do work if you pass them to printf(). You can have an HTML file parametrized with printf() for example.

xxd -i printf-template.html > printf-template.html.h

I assume you can embed anything this way; strings, images, 3D models, etc. This seems cross-platform enough. I'm starting to wonder if the new #embed C standard proposal is really needed, or just bloat now. (Even parameterized #embed sounds like something replaceable with some UNIX piping before you pass the data to xxd -i).

Author Public Key
npub1aj05n6h74ys35hfujyddczfcmr4drhs79xtrfdxw8sutdq2gnw9q994pgc