News for hackers. Stuff that matters.
Re:Rust vs. C++ Formatting by Gibbon1 on Monday January 16, 2023 @05:25PM (#34406282)
Lets consider #embed which is new for C23. It allows you to import binary blobs of data into a C program at compile time. Like say if you want to import am image or sound file or a table.

How hard was that to implement? Seriously no reason it couldn't have been part of C89. Why wasn't it? Because the compiler writers and the C++ standards commit have no personal use for it. It took 40 years of waiting a five years to get it past the standards committee and just barely.

Those guys also have no interest in printf type functions. And improving printf would be a lot more work than implementing #embed.

Re:Rust vs. C++ Formatting by CountSessine on Monday January 16, 2023 @05:49PM (#34406560)
That’s neat - Borland C had the same thing with the `emit()` pseudo-function with their C89 compiler. I guess Borland’s compiler writers wanted it more than gcc’s?
Re:Rust vs. C++ Formatting by Gibbon1 on Monday January 16, 2023 @06:08PM (#34406767)
Consider the difference between what a compiler does and say a video game or embedded firmware. Compilers are old school batch mode programs that import data from a file, parse it, transform it to something, and emit it as a file.
Re:Rust vs. C++ Formatting by panzi on Tuesday January 17, 2023 @12:37AM (#34409484)
You can use ld to turn any file into an object file:

    ld -r -b binary -o foo_txt.o foo.txt
foo_txt.o then has these symbols:

extern const char _binary_foo_txt_start[]; extern const char _binary_foo_txt_end[]; extern const void *_binary_foo_txt_size;

So you need to write your own declarations (it doesn't generate a header file).

_binary_foo_txt_size is weird and has to be used as: (size_t)&_binary_foo_txt_size

Or use (size_t)(_binary_foo_txt_end - _binary_foo_txt_start) instead.