3 ms·
My experience is that most C programmers don't know about many of the caveats about the C programming language. Are you aware that atoi("a"); is undefined beha
by MaulingMonkey 9y ago
My experience is that most C programmers don't know about many of the caveats about the C programming language.
Are you aware that atoi("a"); is undefined behavior? It can crash, it can launch nethack, it can return 0.
- corndoge 9y agoyes I'm aware that parsing a letter as an an integer is undefined behavior, it's in the manual
- MaulingMonkey 9y ago> yes I'm aware that parsing a letter as an an integer is undefined behavior Excellent! > it's in the manual It's not in MSDN: https://msdn.microsoft.com/en-us/library/yd5xkb5c.aspx https://msdn.microsoft.com/en-us/library/yd5xkb5c.aspx It's not in the manpages: https://linux.die.net/man/3/atoi https://linux.die.net/man/3/atoi Cppreference understates it has having an undefined return value, rather than undefined behavior outright: http://en.cppreference.com/w/cpp/string/byte/atoi http://en.cppreference.com/w/cpp/string/byte/atoi Tutorialspoint defines the behavior as returning 0, and fresh2refresh makes no mention of undefined behavior. My eighth google hit for atoi finally, finally, gets it right: http://pubs.opengroup.org/onlinepubs/9699919799/functions/atoi.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/at... If you buy or pirate a copy of e.g. the C89 standard, or refer to one of the free draft versions, it's of course properly documented there too. Neither shows up in the first 50 google results, naturally. And, of course, by google result 9, we're back to square one - incorrectly defining the behavior as being "returning 0": https://en.wikibooks.org/wiki/C_Programming/stdlib.h/atoi https://en.wikibooks.org/wiki/C_Programming/stdlib.h/atoi