0
\$\begingroup\$

I heard some microcontrollers have a poor (or no) support for <string>s as a data type of C/C++ when programming. How to know if a microcontroller supports strings or other C/C++ libraries?

\$\endgroup\$

closed as too broad by Chris Stratton, Michel Keijzers, Voltage Spike, Lior Bilia, Mitu Raj May 2 '18 at 5:33

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Can you provide where you got that information ? It's weird when you say so. \$\endgroup\$ – Long Pham Apr 30 '18 at 9:23
  • 4
    \$\begingroup\$ To be very clear: 'string' is not a hardware concept, it's a programming one. Who needs to "support <string>" is the compiler used. The micro will only see it and manipulate it as a data array, like any other. \$\endgroup\$ – Vicente Cunha Apr 30 '18 at 9:23
  • 1
    \$\begingroup\$ I have yet to find a micro controller compiler which does not support strings or does not have the strcpy strcmp etc. functions. After all they are a lot easier to implement than floats. \$\endgroup\$ – Oldfart Apr 30 '18 at 9:38
  • \$\begingroup\$ @LongPham, stackoverflow.com/a/10745873/4685379. For example in order to include, say, a float into a string, you could use the sprintf() function. For this, you need a couple of functions available in <stdlib.h> and you can't embed stdlib for a tiny microcontroller. So my question is how to know if I can embed a library for a certain microcontroller. \$\endgroup\$ – Dima Dz Apr 30 '18 at 9:48
  • \$\begingroup\$ This is now a very different question. in order to handle floating point numbers the compiler will link in some of the floating point library. You need to know how much space that extra code takes up, and whether it will fit inside your micro. The only way to be sure is to compile your code with the floating point handling and check if it will fit. \$\endgroup\$ – Steve G Apr 30 '18 at 9:53
0
\$\begingroup\$

Any micro will support small arrays of characters. They won't all support the full facilities that std::string or C's printf provide.

So if you need to convert float to string, there's nothing to stop you rolling your own tools to do the job, e.g. to treat a float as two integers separated by a decimal point, and to convert those integers to strings, etc. It's fairly simple basic programming as long as you don't need to handle scientific notation etc.

I shaved about 20k off the size of an executable by doing this (only handling numbers in a restricted range like +/-99999.9999) and eliminating printf.

\$\endgroup\$
  • \$\begingroup\$ it would be useful, I guess, to know what was the total memory for your project before optimization? \$\endgroup\$ – Dima Dz Apr 30 '18 at 14:38
  • \$\begingroup\$ Well at one stage that saving was over half the code. \$\endgroup\$ – Brian Drummond Apr 30 '18 at 19:52
0
\$\begingroup\$

If the software capable of handling std::string fits in memory, then your micro controller supports string.
If not, then it does not.

The question is not, "does the microcontroller support X?".
The question is: "does the microcontroller have enough memory to support X?".

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.