Hi DJ, On Thu, Nov 09, 2023 at 12:30:17PM -0500, DJ Delorie wrote: > Alejandro Colomar <alx@xxxxxxxxxx> writes: > > "Fill a fixed-width buffer with characters from a string and pad with > > null bytes." > > The pedant in me says it should be NUL bytes (or NUL's), not null bytes. > nul/NUL is a character, null/NULL is a pointer. Here's what man-pages(7) (written by Michael Kerrisk) says: NULL, NUL, null pointer, and null byte A null pointer is a pointer that points to nothing, and is nor‐ mally indicated by the constant NULL. On the other hand, NUL is the null byte, a byte with the value 0, represented in C via the character constant '\0'. The preferred term for the pointer is "null pointer" or simply "NULL"; avoid writing "NULL pointer". The preferred term for the byte is "null byte". Avoid writing "NUL", since it is too easily confused with "NULL". Avoid also the terms "zero byte" and "null character". The byte that termi‐ nates a C string should be described as "the terminating null byte"; strings may be described as "null‐terminated", but avoid the use of "NUL‐terminated". I don't necessarily agree with all of that, but mostly. I don't agree with not saying null character, because as well as we have the null wide character (L'\0'), using null character for '\0' makes it symmetric. Other than that, I mostly agree with Michael. Here's what I think of these terms: - NULL is a null pointer constant (as well as 0 is another null pointer constant). - A null pointer is a more generic term that includes a run-time null pointer as well. - The null byte is 0. - The null character, '\0', is composed of a null byte. - The null wide character, L'\0' is composed of several null bytes. - NUL is the ASCII name of the null byte, or maybe is it null character here? It's a bit muddy. I use null byte for padding, and null character for the string terminator, to make a stronger difference between strings and null-padded fixed-width arrays. I need to review string_copying(7) to make sure I was consistent in this regard. Colloquially, I find it fine to write NULL instead of null pointer (even for non-constant cases), and NUL instead of any of "null character", "null byte", or "null wide character", but for being precise, I prefer "null something". Cheers, Alex -- <https://www.alejandro-colomar.es/>
Attachment:
signature.asc
Description: PGP signature