3 ms·
Whether the string ends in NULL or not is up to you as a programmer. It's only an array of bytes, even though the convention is to NULL-terminate it. Well mayb
by BenjiWiebe 1y ago
Whether the string ends in NULL or not is up to you as a programmer. It's only an array of bytes, even though the convention is to NULL-terminate it.
Well maybe more than just a convention, but there is nothing preventing you from setting the last byte to whatever you want.
- mrheosuper 1y agoEverything in C is just array of bytes, some would argue uint32_t is just array of 4 bytes. That's why we need convention. A string is defined as byte array with Null at last. Remove the Null and it's not a string anymore.
- int_19h 1y agoThat's only one possible convention, and it's not a particularly good one at that.
- MaxBarraclough 1y ago> Everything in C is just array of bytes, some would argue uint32_t is just array of 4 bytes That isn't how the C language is defined. The alignment rules may differ between those two types. Consider also the need for the union trick to portably implement type-punning in C. Also, the C standard permits for CHAR_BIT to equal 32, so in C's understanding of a 'byte', the uint32_t type might in principle correspond to just a single byte, in some exotic (but C compliant) platform. No doubt there are other subtleties besides.