I understand what said functions do, but I can't guess how their names were created, except that the last letter is from the return type.
-
1Programmers used to be lazy, and they wanted short name for their functons so it was faster to write these with a keyboard. 4 letters was quite enough, it was even considered too long, but they kept it anyway, being too lazy to change them. – Antoine Pelletier Jun 15 '16 at 14:51
-
**a**rray to **i**nt – el.pescado - нет войне Jun 15 '16 at 14:52
-
@AntoinePelletier I wouldn't say lazy, I would say memory constrained. Remember C was written on incredibly limited hardware (ram was measured in bytes or perhaps kilobytes). I believe C originally had an 8 character limit on function names. I personally worked on a system that you couldn't chain compile and link on the same command line due to their being /only/ 64Kb of ram on the whole (multiuser) system ! – Neil Jun 15 '16 at 16:16
-
@Neil i was just joking, i should have added a Chuck Norris fact through my post to make it obvious – Antoine Pelletier Jun 15 '16 at 17:16
-
1@AntoinePelletier I missed that whooshing sound when your joke flew over my head :-) – Neil Jun 16 '16 at 09:26
1 Answers
atoi -> ASCII to integer.
atol -> ASCII to long.
atof -> ASCII to floating.
stoi -> string to integer.
stol -> string to long.
stoll -> string to long long.
stof -> string to float.
stod -> string to double.
stold -> string to long double.
atoi
, atol
, atof
come from C
and its godfather most probably is considered to be Ken Thompson the co-creator of the UNIX operating system and the creator of the B programming language which is the predecessor of the C programming language. The names are mentioned in the first UNIX Programmer's Manual November 3, 1971 and as you can see in the owner's label ken
is mentioned which is the nickname of Ken Thomson:
stoi
, stol
, stoll
, stof
, stod
and stold
got in C++ since C++11. Consequently, the naming must have been a unanimous decision of the C++ committee. The original proposal N1803 though dates back in 2005. I couldn't find in the proposal why the named these functions after these names. My guess is that probably they wanted to keep the uniformity with their C "equivalents" mentioned above.

- 41,839
- 11
- 94
- 168
-
3The interesting fact is, that these functions would work for EBCDIC character tables equally well. – πάντα ῥεῖ Jun 15 '16 at 14:47
-
2
-
@JaredBurrows I wasn't conceived even as a concept in my father's mind back then. – 101010 Jun 15 '16 at 19:24
-
@101010 Alright. I was being serious because I still have a C book that my father gave me. – Jared Burrows Jun 15 '16 at 20:04
-
1@JaredBurrows I guess is nice to have a father that lived the beginning of the Information Age, many things to talk about :). From where I come from though, my parents weren't such fortunate, at that time it would be an achievement if a kid would finish the primary. Books were rare and they didn't have electricity in many parts of the country. Thanks to USA the land of the free and the home of the brave we have the internet now and these books as many others are available for everyone online. – 101010 Jun 16 '16 at 07:07
-
@101010 Awesome to here! Thanks for the great answer and the image. – Jared Burrows Jun 16 '16 at 14:07