Offline
Full Member
Karma: 2
Posts: 212
|
 |
« on: August 04, 2012, 01:43:05 pm » |
When looking at the reference there is no atoi() function see http://arduino.cc/en/Reference/HomePageStill 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.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 983
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #1 on: August 04, 2012, 01:45:51 pm » |
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/
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Ayer, Massachusetts, USA
Offline
Edison Member
Karma: 27
Posts: 1102
|
 |
« Reply #2 on: August 04, 2012, 01:48:07 pm » |
When looking at the reference there is no atoi() function see http://arduino.cc/en/Reference/HomePageStill 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.
|
|
|
|
|
Logged
|
|
|
|
|
Anaheim CA.
Offline
Edison Member
Karma: 31
Posts: 2309
Experienced old Whitebeard with a Full head of Hair...
|
 |
« Reply #3 on: August 04, 2012, 03:25:55 pm » |
Tom Carpenter... Does that also include "sprintf"?
Doc
|
|
|
|
|
Logged
|
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
|
|
|
|
|
|
Offline
Full Member
Karma: 2
Posts: 212
|
 |
« Reply #5 on: August 04, 2012, 04:29:52 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 983
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #6 on: August 04, 2012, 04:34:46 pm » |
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.
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Offline
Full Member
Karma: 2
Posts: 212
|
 |
« Reply #7 on: August 04, 2012, 05:36:05 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6388
-
|
 |
« Reply #8 on: August 04, 2012, 06:45:28 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Ayer, Massachusetts, USA
Offline
Edison Member
Karma: 27
Posts: 1102
|
 |
« Reply #9 on: August 04, 2012, 07:57:20 pm » |
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.
|
|
|
|
« Last Edit: August 05, 2012, 07:44:37 pm by MichaelMeissner »
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 983
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #10 on: August 04, 2012, 08:03:06 pm » |
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.
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Ayer, Massachusetts, USA
Offline
Edison Member
Karma: 27
Posts: 1102
|
 |
« Reply #11 on: August 04, 2012, 08:38:35 pm » |
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. 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.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 983
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #12 on: August 04, 2012, 08:49:24 pm » |
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);
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Grand Blanc, MI, USA
Offline
Faraday Member
Karma: 43
Posts: 2505
"We're a proud service of the Lost Electricity Reclamation Agency"
|
 |
« Reply #13 on: August 05, 2012, 08:45:37 am » |
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/avrdudeArduino is built on top of this toolchain consisting of AVR-GCC, AVR-Libc, and AVRDUDE.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 15
Posts: 1009
Arduino rocks
|
 |
« Reply #14 on: August 05, 2012, 03:26:42 pm » |
I think in WinAVR, the version of sprintf() supplied doesn't support floating point nor long long arithmetic. For comparison,
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
|
|
|
|
|
Logged
|
|
|
|
|
|