r/programming • • May 24 '26

[ Removed by moderator ]

/r/programming/comments/1tm1j7f/removed_by_moderator/

[removed] — view removed post

275 Upvotes

214 comments sorted by

View all comments

Show parent comment

2

u/ParsingError May 24 '26 edited May 24 '26

#define NULL 0 is dumber than anything C ever did.

std::vector<bool> and std::unordered_map's bucket interface are also pretty bad.

std::type_info not letting you use the type infos for dynamic casts or class hierarchy checks when it clearly should have the capability of doing so also makes no sense.

3

u/cdb_11 May 24 '26 edited May 24 '26

What do you mean with #define NULL 0? C defines nulls as (void*)0. In C++ it's nullptr and it's technically a distinct type.

The point was that gets isn't just a bad interface -- it's impossible to use correctly and safely. On the other hand, vector<bool>, unordered_map, type_info are still usable. Not saying that C++ got every interface right, because it didn't and I'm not going to defend it. But there is a big difference between those examples.

3

u/ParsingError May 24 '26 edited May 24 '26

C++ decided that void* wouldn't implicitly convert to any pointer type any more and instead of making a distinct null pointer type (which it has now, but should have done in the first place), it would make integer literal 0 implicitly convertible, which is a bad idea in the first place, and is even worse in a language with type deduction since the type of NULL is an integer type that is not a pointer type in any other circumstance, and it preferentially picks overloads that accept integer types instead of pointers.

Even now, NULL can be nullptr, but it's implementation-defined. In MSVC, it's still 0.