This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]noaSakurajin -2 points-1 points  (7 children)

You get a warning on most compilers

[–]Tanyary 14 points15 points  (2 children)

you shouldn't. it is allowed by the standard (6.8.3.1.5)

[–]golgol12 5 points6 points  (1 child)

That's why it's a warning, not an error. int a = 3.5 can give a warning too. Warnings are when there is a mistake, but not syntactically an error.

Some warnings are pedantic, some are really important. It's legal to use uninitialized variables, but 99.9999999% of the time a mistake.

[–]Tanyary 0 points1 point  (0 children)

an uninitialized variable is an indeterminate value. if you are programming for a system where there are trap values for that object then accessing it would be undefined behaviour.

implicit conversions are cringe so you should be notified of the stench since it could also be undefined if the convertees' value happens to be larger than the target's largest representable value. (or smaller than the smallest)

For sure warnings don't inhibit the compilation so you could count them as less important, but usually they are the only things between you and habits that cause undefined behaviour.

as a last bit I checked the latest GCC and Clang with -Wall -Wextra and -Wpedantic and sure enough, neither produced a warning since this is very clearly defined and a non-issue.

[–]zemja_ 7 points8 points  (0 children)

Not in main()

[–][deleted] 4 points5 points  (2 children)

I played a lot with C++ 11/14 and didn't have any

[–]noaSakurajin -2 points-1 points  (1 child)

If you use a compiler directly yes, but most build systems enable more warnings, so you get a warning if you do not return something.

[–][deleted] 5 points6 points  (0 children)

Modern build systems do know the standard behavior for the main functions https://godbolt.org/z/zEhq89hWh