Comment by duped
3 years ago
sure, but if it's a string that requires it to be null terminated, there's no reason the compiler can't solve that problem
3 years ago
sure, but if it's a string that requires it to be null terminated, there's no reason the compiler can't solve that problem
How does the compiler know if an array is a string or not?
It doesn't have to, you just add a zero byte at the end of the embedded byte sequence in the object file. It's up to the programmer to make the choice how to interpret that.
That said for binary embeds you almost always need the length embedded as well, which has been the case for every tool I've used to embed files in object code. You usually get something like
> It doesn't have to, you just add a zero byte at the end of the embedded byte sequence in the object file. It's up to the programmer to make the choice how to interpret that.
Like, are you proposing that the ideal semantics for `#embed "foo"` if foo contained 0x10 0x20 0x30 0x40 to be to expand to `16, 32, 48, 64, 0`? That seems more annoying than the opposite, given that:
> That said for binary embeds you almost always need the length embedded as well, which has been the case for every tool I've used to embed files in object code. You usually get something like
TFA demonstrated it by relying on sizeof() of arrays doing the right thing:
You'd need to change this to subtract one every time, which sounds more annoying when embedding binary resources than adding the zero to strings would be.