logoalt Hacker News

mathisfun123yesterday at 5:04 PM3 repliesview on HN

> Probably not something you’d encounter in practice

it's actually probably the most common footgun you'll encounter in practice: non-void functions with no return statements just keep executing past their end. ask me how i know.

compile with -Wreturn-type if you want to avoid such things...


Replies

kouosiyesterday at 5:26 PM

> compile with -Wreturn-type if you want to avoid such things...

Isn't -Wreturn-type enabled by default in both gcc and clang atleast for c++?

show 1 reply
drdexebtjlyesterday at 8:23 PM

C on the other hand puts an implicit `return 0` at the end, but only on the main function for some reason. Very weird.

show 1 reply
mitxelatoday at 12:38 AM

In C. In C++ it's an error to not return, as it should be.

show 1 reply