4 ms·
After 40 years of dicking around the C21 has an #embed preprocessor feature. I think which allows you to write stuff like const char python_script_foo [] =
by Gibbon1 4y ago
After 40 years of dicking around the C21 has an #embed preprocessor feature.
I think which allows you to write stuff like
const char python_script_foo [] =
{
#embed <foo.py.wav>
};
Would be useful for embedded scripting. Especially for firmware.
- JonChesterfield 4y agoThis was of course available though inline assembly or code generators from the beginning. So C21 is more complicated for the extra looks-like-prepreprocessor-but-probably-isn't syntax with no increase in expressivity.
- dotancohen 4y agoHow could that not be a preprocessor? Or are you suggesting that the compiled binary will now include a Python interpreter?
- unwind 4y agoIt is a preprocessor directive, the result must be as if the contents of the file were inserted byte by byte as integer literals. See [1] for more information (which, btw, also states that #embed is in C23, not C21 (which doesn't exist as far as I know)). [1]: https://thephd.dev/finally-embed-in-c23 https://thephd.dev/finally-embed-in-c23
- JonChesterfield 4y agoIf it's implemented in the preprocessor - e.g. expanding to a comma delimited char array - then the performance justification for adding it to the compiler is lost. However you might be using "preprocessor directive" in the language semantic phase sense, not in the "preprocessor does it" sense.
- Gibbon1 4y agoIt's inserted as a binary blob by the compiler. So just a simple copy of the file contents.