Post by Tim RentschPost by Keith ThompsonI just about always use NULL, not 0, when I want a null pointer
constant. Similarly, I use '\0', not 0, when I want a null character,
0.0 when I want a floating-point zero, and false when I want a Boolean
zero. I just like being explicit.
Me too.
But at the same time I realize that this is a habit forced upon my by
circumstances, by necessity. C (as well as C++) at its beginning (and
when I started to use the language) was not very well-suited for
type-agnostic/DRY programming. It had a few odd features/idioms
acknowledging the possibility, but by large both languages were
predominantly type-aware or type-explicit. I reckon, this is actually
what made you to "like" such explicitness. But it is pointless to talk
about "liking" something, when one really had no choice.
The moment C++ realized the full power of generic/template
programming, it immediately rushed head-over-heels into type-agnostic
programming style. It was `auto` and `decltype` initially, which then
just opened the proverbial floodgates, triggering the avalanche of
additional features targeted at the type-agnostic programming
style. Many in C++ world still protest it, claiming that old-style
type-explicit code is "easier to read", but they are nothing more than
overgrown kids being reluctant to take the training wheels off their
bikes (since they make it "easier to ride"). There no doubt anymore
than type-agnostic programming is the next big thing for C++.
The same goes for C. C is not C++, of course, but with the
introduction of `typeof` in C23 and, hopefully, better `_Generic`
appearing one of these days, one can hope that being type-explicit is
a thing of the past in C as well.
So, no. While I too prefer to use `NULL` for pointers and '\0' for
character constants, I realize that do it out of deep-seated habit, or
for nostalgic/luddite reasons mostly. Plain undecorated `0` as a
universal type-agnostic constant should really be my choice everywhere
today.
Hmm. I like the idea of a type-agnostic way to express a "zero" value,
especially in a language that lets you write type-generic code. But I
constant of the specific type int. C's use of 0 for all scalar types
strikes me more as an historical accident than a design feature.
And of course not all code needs to be type-agnostic.
any type (there are probably off-topic subtleties I'm missing). In C23,
not as an expression.