logoalt Hacker News

Rucadiyesterday at 7:49 AM2 repliesview on HN

auto has a good perk, it prevents uninitialized values (Which is a source of bugs).

For example:

auto a;

will always fail to compile not matter what flags.

int a;

is valid.

Also it prevents implicit type conversions, what you get as type on auto is the type you put at the right.

That's good.


Replies

feelameeyesterday at 9:09 AM

uninitialized values are not the source of bugs. This is a good way to find logic errors in code (e.g. using sanitizer)

show 1 reply
jb1991yesterday at 8:02 AM

This is indeed exactly correct. Probably on its own this is the most important reason for most people to use it, as I think most of the millions of C++ developers in the world (and yes there are apparently millions) are not messing with compiler flags to get the checks that probably should be there by default anyway. The keyword auto gives you that.