Go Down

Topic: How can I simplify this simple code? (Read 4221 times) previous topic - next topic


Can someone please direct me to an article (Or give me an explanation) on why using String variables are usually bad in C++/Arduino?

There is a specific problem with the Arduino String class because it exposes a bug in the Arduino memory management. But using strings to represent numbers is generally a bad idea anyway because you then need to parse the string to get the number each time you need to use it. This slows your code down and introduces potential problems in any situation where the string might not contain a valid number. Best to treat numbers as numbers - if you're given a string, parse it to a number once and use the number from then on - if you need to output a string, format the number as a string at the point you need to output it.

Go Up