Recently, I have used Arduino to build LoRa gateways and nodes in the development of the Internet of Things, and I found that some strange phenomena are always encountered when calling String. After investigation, it was found that it was caused by overloading of the []= operator elsewhere.
For convenience, we used [LoRa-Socket](https://github.com/iotcat/lora-socket) and [ArduinoJSON](https://arduinojson.org/) as dependencies when developing nodes. We found that these two dependencies perform well when used separately, but if used in the same project file, it will cause some weird problems.
## Situation One
When calling a function through a pointer, the String parameter passing is abnormal. code show as below:
In this case, we found that the value of msg and other String in this function is all normal, but it was not successfully passed to _f. After a series of Sao operations, we come to the following conclusions:
- Found that if you change String to int or other types, the parameters passed to _f are all normal. Only the String and char types are problematic.
- We tried to convert String to other types, and then back, but to no avail.
- The declaration of global variables of type String or char will crash the microcontroller.
- When we delete the ArduinoJSON dependency, the passing of String parameters is normal.
We can conclude that this strange phenomenon is caused by the conflict with the ArduinoJSON package.
## Situation Two
When using [ArduinoVector](https://github.com/tomstewart89/Vector) to make a String type Vector, we also discovered the instability of the String type. The magic is that this phenomenon only occurs in the use of String, other types such as int work well.
These instabilities can be summarized as follows:
- Truncated during assignment
- String values are locally out of order
- Part of the String value is garbled
- It will fail when passed as a parameter to the function, and it will be empty (similar to case 1)
## Summary
Through the above two cases, we can preliminarily conclude that this is due to the conflict between the overload of the []= assignment operator and String. As long as you use []= to redefine String, string weird problems may occur.