0

Anyone know what the source of the name of the function atol for converting a string to an long?

I thought about Array To long but it's not sounds to me true.

yehuda corsia
  • 265
  • 3
  • 8
  • 2
    It's Ascii TO Long, just as atoi is Ascii TO Int and atof is Ascii TO Float. – Tom Karzes Nov 09 '17 at 08:22
  • 2
    Actually, this is a misnomer, as `atoi()` must work on machines with a different primary character encoding (as long as the codes for numbers are in sequence). I've seen the alternative spelling as "*anything* to long", but that's not really good either ... –  Nov 09 '17 at 08:27

2 Answers2

4

ASCII To Long is what atol(3) means (in the early days of Unix, ASCII was only used, and IIRC was mentioned in the K&R book)

Today we usually use UTF-8 everywhere, but atol still works (since UTF-8 for digits uses the same encoding than ASCII)

On C implementations using another encoding (e.g. EBCDIC) atol should still do what is expected (so atol("345") would give 345), since the C standard requires that the encoding of digit characters is consecutive. Its implementation might be more complex (or encoding specific).

so today, the atol name don't refer anymore to ASCII. The C11 standard n1570 don't mention ASCII (as mandatory) IIRC. you might rewrite history by reading atol as anything to long even if historically it was ASCII to long.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • "C standard requires that the encoding of digit characters is consecutive." is true, yet `ato*()` also needs to cope with white-space, `+`, `-`, etc.whose encoding are not specified much. IOWs this good answer stands fine w/o the 3rd paragraph. – chux - Reinstate Monica Nov 09 '17 at 12:13
  • I do believe that it is important to remind that C might not use ASCII (even if coding with EBCDIC is *very* unusual today). But the name of `atol` relates to the time where C was only on ASCII systems. – Basile Starynkevitch Nov 09 '17 at 12:17
1

It's Ascii to long, the same convention is used for atoi etc.

Colin
  • 3,394
  • 1
  • 21
  • 29