4 ms·
I added one of those features, #embed, to my Cedro C source code preprocessor and posted about it yesterday: https://news.ycombinator.com/item?id=32341326 https
by AlbertoGP 4y ago
I added one of those features, #embed, to my Cedro C source code preprocessor and posted about it yesterday: https://news.ycombinator.com/item?id=32341326 https://news.ycombinator.com/item?id=32341326
Here is the direct link: “Use #embed from C23 today with the Cedro pre-processor” https://sentido-labs.com/en/library/cedro/202106171400/use-embed-c23-today.html https://sentido-labs.com/en/library/cedro/202106171400/use-e...
As I write there, “The advantage of using Cedro is that the source code is the same and this way it is very easy to use different compilers, only adding or removing the #pragma line.”
I also added a command-line option to embed the bytes as strings instead of byte literals; embedding an 8 MB file, the strings variant compiled between 28 and 72 times faster depending on which compiler I used, gcc or clang. It is more efficient, but less compatible, that’s why it’s optional.
I’m considering adding some low-hanging fruit, like the number literal separators: 1'384'849 → 1384849
- kibwen 4y agoFor number literal separators, I'd suggest using underscore rather than apostrophe. Ada, C#, D, Haskell, Java, Kotlin, OCaml, Perl, Python, PHP, Ruby, Go, Rust, Julia, and Swift all use the underscore. C++ wanted to use the underscore, but was forced to use the apostrophe because of user-defined literals.
- AlbertoGP 4y agoYes, I meant implementing it as specified for C23 which was done for compatibility with C++, although I do prefer the underscores. Maybe that’s a better idea, implement it with underscores in Cedro as it does not need C++ compatibility. Edit: alright, it works. I also extended the parser to accept the apostrophe as part of number tokens. The only thing it does is to remove the underscores when writing. I might need another command line option to specify whether the output should be C23: 1_234_567 → 1'234'567 or pre-C23: 1_234_567 → 1234567 1'234'567 → 1234567