Live data from Hacker News

C/C++ Embedded Files (2013)

4rknova.com

31–40 of 57 posts

Re: C/C++ Embedded Files (2013)

#31
post #2

Outdated, modern solution is baked in now https://en.cppreference.com/w/c/preprocessor/embed

The thing that always irks me about c++ is this sort of thing: > Explanation 1) Searches for the resource identified by h-char-sequence in implementation-defined manner. Okay, so now I have to make assumptions that the implementation is reasonable, and won't go and "search" by asking an LLM or accidentally revealing my credit card details to a third party, right? And even if the implementation _is_ reasonable the onl…

#include also searches for the file you give it in an "implementation-defined manner", so if you have this complaint about #embed, you ought to also consider #include equally problematic

Re: C/C++ Embedded Files (2013)

#33
post #2

Outdated, modern solution is baked in now https://en.cppreference.com/w/c/preprocessor/embed

The thing that always irks me about c++ is this sort of thing: > Explanation 1) Searches for the resource identified by h-char-sequence in implementation-defined manner. Okay, so now I have to make assumptions that the implementation is reasonable, and won't go and "search" by asking an LLM or accidentally revealing my credit card details to a third party, right? And even if the implementation _is_ reasonable the onl…

this take is basically equivalent to "don't write software unless you write the stack from scratch."

Re: C/C++ Embedded Files (2013)

#34

You can also do it using ld - it's something like ld -r --format binary -o out.o , although you do want some build system assistance to generate header files allowing you to access the thing (somewhat similar to the assembly example here). It's a bit of a performance but I strongly prefer it to generating header files in the earlier options - those header files can end up being _very_ large (they generally multiply u…

The special ld argument is a gnu thing, it's not portable and at least lld doesn't support it. https://github.com/jcalvinowens/ircam-viewer/commit/17b3533b...

It's also not reliable for most architectures.

Re: C/C++ Embedded Files (2013)

#35
you could also use the linker to link in basically anything into the file where u like.

it might be a bit 'arcane' way to do it idk... but to me it always seemed the logical way.. u can also define symbols etc around it and use extern in ur c/cpp program to reference those.to access the data in light of dynamic linking / alsr etc.

here is some resource on it with some examples: https://wiki.osdev.org/Linker_Scripts

u can include any file. another executable, images, etc. etc. no need for weird stuff in the c sources?

on the flipside, is there a benefit of doing it inside the source code?? (apart from not having to roll ur own linker script and learn that dragon?)

Re: C/C++ Embedded Files (2013)

#36
post #2

Outdated, modern solution is baked in now https://en.cppreference.com/w/c/preprocessor/embed

let me know when my embedded target's compiler is C23 compliant (i mean, i whish. we may be getting C11 or even C17 some times next year but i'm not holding my breath)

What are you targetting? for instance all ESP32 now support GCC15 which has support for #embed. AVR also has GCC 15 toolchains for months, as well as ARM which also allows you to target STM32 and Nordic nRF stuff.

Re: C/C++ Embedded Files (2013)

#37

Earlier quoted context omitted.

Python is pretty much mandatory for Linux systems nowadays, unless you're dealing with something really minimalist or trying to be very portable it's safe to rely on.

> it's safe to rely on Is there any guarantee they won't break backwards compatibility again?

I wrote this almost ten years ago and it still works fine: https://github.com/jcalvinowens/diveutils/blob/master/consta...

Arguably it could be a little C helper, but I wanted this particular piece of the project to be more accessible so I used a scripting language.

Re: C/C++ Embedded Files (2013)

#38
post #2

Outdated, modern solution is baked in now https://en.cppreference.com/w/c/preprocessor/embed

let me know when my embedded target's compiler is C23 compliant (i mean, i whish. we may be getting C11 or even C17 some times next year but i'm not holding my breath)

What current embedded target in $this_year doesn't have a C11 compiler? I'll send you $5 if you can name one.
Post reply on HN