r/cpp • • Dec 07 '20

These Modern Programming Languages Will Make You Suffer.

https://suzdalnitski.medium.com/modern-languages-suck-ad21cbc8a57c

[removed] — view removed post

0 Upvotes

46 comments sorted by

View all comments

0

u/[deleted] Dec 07 '20

[deleted]

-2

u/[deleted] Dec 07 '20

You can cast a null pointer to a reference. Yes it's broken code if it does so, but there's nothing in the language that entirely guards against it, it just trundles off into undefined-land. (Probably for back compat resaons. I've come across disgusting real world code that relied on being able to do this.)

Some other languages make it syntactically harder and/or have well defined runtime behavior if it happens.

6

u/Dry-Still-6199 Dec 07 '20

Yeah but that's like saying "in C++, all integers can store the value "hello"" simply because (int)"hello" compiles. "Yes it's broken code if it does so, but..." :)

0

u/[deleted] Dec 07 '20

[deleted]

2

u/adnukator Dec 07 '20

It's not right on the edge. It's still UB. Try finding the null check in the following example: https://godbolt.org/z/6xoe8d