-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String constructor and concat with int64_t results in "ld" #7760
Comments
That's going to be an issue with WString.cpp/h. Still learning argument matching for C++, but here goes:
Possible += matches in WString.h:
Possible matches in WString.cpp:
NOTE: I have tried using |
Nope, I guess the constructor is one of the few things I'm quite certain there will not be any mismatch as it is declared with
I think that's the real problem here. As a work-around for my own code, I have made these functions. String ull2String(uint64_t value, uint8_t base) {
String res;
if (value == 0) {
res = '0';
return res;
}
while (value > 0) {
res += String(static_cast<uint32_t>(value % base), base);
value /= base;
}
int endpos = res.length() - 1;
int beginpos = 0;
while (endpos > beginpos) {
const char c = res[beginpos];
res[beginpos] = res[endpos];
res[endpos] = c;
++beginpos;
--endpos;
}
return res;
}
String ll2String(int64_t value, uint8_t base) {
if (value < 0) {
String res;
res = '-';
res += ull2String(value * -1ll, base);
return res;
} else {
return ull2String(value, base);
}
} But of course, I have no clue where other code may be using those |
@TD-er I've been thinking about this and decided to investigate String.h by comparing against related projects. https://github.com/arduino/ArduinoCore-API/blob/master/api/String.cpp "long long" (int64_t) support: arduino-esp32 ArduinoCore-API ESP8266 Proposed fixes: https://github.com/espressif/arduino-esp32/commits/master/cores/esp32/WString.cpp |
What does surprise me is that the Arduino String class among ESP8266 and ESP32 are not the same. |
I also think they should match. However they are maintained by different owners. I know that ESP8266 handles constants in flash differently than ESP32. Right now the files are too different for me to sync up, but I can bring over a few changes that I do understand. |
Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
@TD-er Try the proposed PR and see if that fixes your issue. Testing appreciated! |
I will tomorrow, but probably not before the evening. |
Thank you @TD-er and @mrengineer7777 for investigating it! |
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue espressif#7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266)
WString Fix int64_t Fixed int64_t String support. Resolves issue #7760. Background: sprintf on esp32 doesn't support "%lld" parameter. It's possible to recompile the underlying libraries to add that option, but I have an easier solution. This has already been solved in ESP8266 version of WString by replacing sprintf() with itoa/ltoa/lltoa. This PR does the following: Fixes integer print issues by replacing sprintf() with itoa/ltoa/lltoa Moves concat(long long num), concat(unsigned long long num) location (match ESP8266) Cleans up code formatting (matches ESP8266) Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
Board
Any
Device Description
Hardware should not matter, but this test was done on a:
ESP32-D0WDQ5-V3
Hardware Configuration
Not important
Version
v2.0.6
IDE Name
PlatformIO
Operating System
Windows 11
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
115200
Description
Constructor and concat with
long long
(int64_t) is not working as it should.Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: