← Back to context

Comment by nyanpasu64

3 years ago

I don't think adding a null terminator is useful for binary files which are not null-terminated strings, and may even have embedded 0 bytes in the middle.

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

          const size_t My_FILE_LENGTH = ... ;
          const uint8_t MY_FILE[] = { ... };

      1 reply →