-
Notifications
You must be signed in to change notification settings - Fork 7.6k
micros() and millis() are uint32_t (unsigned int), instead of unsigned long #384
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
Comments
unsigned long on AVR is 32 bit ;) Just FYI. |
I'm not sure if it's a bit issue, but it's definitely a typecast issue in respects to keeping with the Arduino SDK standard at the least. Like I said, I primarily noticed this when porting ESP8266 code to ESP32 and one library I use to measure pulse width frequencies failed to work because millis() and micros() were not the same typecast as was expected, which was unsigned long. When using millis and micros, I've always seen unsigned long's used in reference to it. |
unsigned long in ambiguous. Why not use uint64_t, for example, this is specific and cannot be confused with anything else. |
As @erenfro correctly noted, this isn't a bit width issue, as both int and long are 32 bit on Xtensa. However in C++ |
Merged :) |
Arduino-esp32/cores/esp32/esp32-hal.h
Shows that millis() and micros() are uint32_t types, which is unsigned int's. This is incompatible with the ESP8266 code which was unsigned long types. This causes portability to go downhill due to type differences.
It causes problems in portability in the SDK itself. How I found it specifically in my case is I have a function that is passed the reference of either millis or micros to use to determine timing mathmatics for frequency calculations. It was expecting the pointer to be an unsigned long because that's what micros and millis are in everything Arduino, except for ESP32's codebase.
It's also timing as well, because those numbers are long for the reasons of longevity. millis has about the time span of about 50 days, while micros has about 70 minutes. They can do that because of the size of an unsigned long, but can't with an unsigned int because the number isn't as large. This may not be the case of the ESP8266 or ESP32 specifically, however the Arduino SDK documents and uses unsigned long as part of the official documentation and implementation.
The text was updated successfully, but these errors were encountered: