atoi() function where does it come from ?

When looking at the reference there is no atoi() function see http://arduino.cc/en/Reference/HomePage Still however i see people advice or use it here, where does this program verb belong too, is there a binary to be included for it ? Or is the reference not up to date, if so can someone please update it.

It isn't an Arduino function, its part of the C++ standard libraries (stdlib.h), which are included automatically in all sketches.

http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/

PGTBOOS: When looking at the reference there is no atoi() function see http://arduino.cc/en/Reference/HomePage Still however i see people advice or use it here, where does this program verb belong too, is there a binary to be included for it ? Or is the reference not up to date, if so can someone please update it.

Atoi, atol, and atoll are all defined in the ISO C standard (7.20.1.2 for C99). I would imagine that it is the C++ standard, but I don't happen to have the C++ standard right here.

Tom Carpenter... Does that also include "sprintf"?

Doc

sprintf() is from a different C library (stdio.h), but it is included in Arduino yes.

The vast majority of functions from these four libraries are all included.

http://www.cplusplus.com/reference/clibrary/cstdlib/
http://www.cplusplus.com/reference/clibrary/cstring/
http://www.cplusplus.com/reference/clibrary/cstdio/
http://www.cplusplus.com/reference/clibrary/math/
http://www.cplusplus.com/reference/clibrary/cctype/
http://www.cplusplus.com/reference/clibrary/cstring/

For more info as to which are included, if you have windows, you can look at the header files which are all here:
\hardware\tools\avr\avr\include
On Mac the are located at:
<right click arduino.app, show Package contents>/Contents/Resources/Java/hardware/tools/avr/avr/include/

Then shouldnt the arduino reference also include these commands ? If some basic c / c++ commands can also be run inside the sketches and currently most commands are included then those should be to named

Arduino is C++, which means there is little point rewriting the C++ reference . The Arduino reference is there for more Arduino specific stuff. It would be highly sensible if there was a link (or several) in the Arduino Reference to the C++ reference.

ok well it are not that many functions I see http://www.cplusplus.com/reference/clibrary/cstdlib/ for people who start with arduino (like me and many others), it might be handy to also include them in the reference or at least mention a link to a page that does explain it, so people are aware it isnt the full command set.

There is a link from the Arduino reference page to the AVR reference page where all the runtime libraries that are available are defined. Note that the AVR library implementations have some optional components and the Ardunio IDE does not include all options, for example printf etc do not include support for formatting floating point values.

Docedison: Tom Carpenter... Does that also include "sprintf"?

Doc

In the past when I did compilers for other embedded processors, the problem with using any of the *printf functions is they pull in the whole floating point and long long arithmetic support functions. On some of the ports, *printf would use 3/4 of the total memory for all of the support functions. So, the functions are convenient to use, but they can be big.

MichaelMeissner: In the past when I did compilers for other embedded processors, the problem with using any of the *printf functions is they pull in the whole floating point and long long arithmetic support functions. On some of the ports, *printf would use 3/4 of the totally memory for all of the support functions. So, the functions are convenient to use, but they can be big.

I think in WinAVR, the version of sprintf() supplied doesn't support floating point nor long long arithmetic. For comparison,

void setup() {}

void loop() {
  char hi[10];
  char lo[] = "Hello";
}

Compiles to 446 Bytes on an Uno

void setup() {}

void loop() {
  char hi[10];
  char lo[] = "Hello";
  sprintf(hi,"%s",lo);
}

Compiled to 554 Bytes on an Uno.

[quote author=Tom Carpenter link=topic=117267.msg882679#msg882679 date=1344128586]

MichaelMeissner: In the past when I did compilers for other embedded processors, the problem with using any of the *printf functions is they pull in the whole floating point and long long arithmetic support functions. On some of the ports, *printf would use 3/4 of the totally memory for all of the support functions. So, the functions are convenient to use, but they can be big.

I think in WinAVR, the version of sprintf() supplied doesn't support floating point nor long long arithmetic. For comparison,

void setup() {}

void loop() {
  char hi[10];
  char lo[] = "Hello";
}

Compiles to 446 Bytes on an Uno

void setup() {}

void loop() {
  char hi[10];
  char lo[] = "Hello";
  sprintf(hi,"%s",lo);
}

Compiled to 554 Bytes on an Uno. [/quote]

That is because GCC optimizes:

sprintf (hi, "%s", lo)

into

strcpy (hi, lo);

If you had printed an integer for instance, it has to call the sprintf function.

Back in the day when I was supporting GCC on embedded platforms, one of the optimizations I kept wanting to do, but never got around to it, is recognizing if you only call *printf with int/char * arguments, to call an alternative function that doesn't support, long, long long, and floating point. However, most of our customers did not use *printf and *scanf due to their memory requirements.

I see what you mean, changing the last bit to this causes it to jump to 2kB

  char num = 2;
  sprintf(hi,"%s%d",lo,num);

PGTBOOS: Then shouldnt the arduino reference also include these commands ? If some basic c / c++ commands can also be run inside the sketches and currently most commands are included then those should be to named

These may help: http://www.nongnu.org/avr-libc/ http://winavr.sourceforge.net/ http://savannah.nongnu.org/projects/avrdude

Arduino is built on top of this toolchain consisting of AVR-GCC, AVR-Libc, and AVRDUDE.

[quote author=Tom Carpenter link=topic=117267.msg882679#msg882679 date=1344128586] I think in WinAVR, the version of sprintf() supplied doesn't support floating point nor long long arithmetic. For comparison, [/quote]

Actually that's not quite true. There is support for printing floating point numbers with vfprintf (the function that all the printf functions call) but it's not linked in by default. You have to change the linker options to get it.

http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#gaa3b98c0d17b35642c0f3e4649092b9f1

WizenedEE: You have to change the linker options to get it.

And therein lies the problem for Arduino. The Arduino IDE does not allow you change the linker options. (Although can set the linker options if abandon the Arduino IDE for mpide or use make with your own makefiles)

I as more interested in the formatted print functions than managing longs or floats. I usually do that myself beforehand. Long way round but it works for me at my poor level of comprehension of the language. It might take a few more lines of code but it works. I have little interest in floats anyway... too much like the job I retired from. This is my retirement hobby not a vocation. B'sides the Arduino is more a teaching platform than any kind of really accurate analog device and those I can buy as peripheral chips and talk to then with one serial bus or another. The Arduino is much better than TV... I don't care for the new stuff and I've seen too much of the old stuff. I noticed my cable box was out of order today and I just unplugged it... If I get a rountoit... maybe I will do something about it. Rountoits are really hard to come by these days though.

Doc

Docedison: The Arduino is much better than TV...

Hear, hear!