Sujet : Re: question about nullptr
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 13. Jul 2024, 01:30:09
Autres entêtes
Organisation : None to speak of
Message-ID : <87h6curv5a.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.13 (Gnus v5.13)
scott@slp53.sl.home (Scott Lurndal) writes:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
On 2024-07-12, Scott Lurndal <scott@slp53.sl.home> wrote:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
On 2024-07-12, Richard Harnden <richard.nospam@gmail.invalid> wrote:
Don't you use '\n'? Surely nobody would say 0x0a?
>
But, see, nobody in their right mind would say '\012` for that. '\0'
an octal escape sequence like '\012', not a role-based character
abstraction like '\n'.
>
Because '\012' is a character. 012 is an int. Using the former
ensures that any overflow will be detected at compile time and make
it clear to any future reader that the author intended it to be a
character, not an integer.
'\012' is a character constant. 012 is an integer constant. Both are
of type int, and both have the same value, 10.
It's true that an octal character constant with a value exceeding
UCHAR_MAX is a constraint violation (like '\400' if UCHAR_MAX is 255),
and if you provide more than 3 digits the result is a multi-character
constant, which is likely to trigger a warning. But any overflow would
almost certainly be the result of a typo, and guarding against that
doesn't strike me as a good reason to use one kind of constant over
another.
Having said that, I absolutely do prefer to use character constants for
character data ('\012' or '\x0a' if I want a character with value 10, or
more likely '\n' if I want a newline). But that's for the benefit of
the reader, not of the compiler.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */