Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification, paragraph 6.3.1.3, the upper 16 bits are discarded.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337https://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification, paragraph 6.3.1.3, the upper 16 bits are discarded.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification, paragraph 6.3.1.3, the upper 16 bits are discarded.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: https://stackoverflow.com/a/13652624/1544337

deleted 146 characters in body
Source Link
user6971
user6971

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification the exact behaviour is implementation-defined, meaning anything may happen (and the exact behaviour is -hopefully- documented somewhere deep down in the Arduino docs)C specification, paragraph 6. What normally happens is that3.1.3, the upper 16 bits are discarded, but you can't rely on that.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification the exact behaviour is implementation-defined, meaning anything may happen (and the exact behaviour is -hopefully- documented somewhere deep down in the Arduino docs). What normally happens is that the upper 16 bits are discarded, but you can't rely on that.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification, paragraph 6.3.1.3, the upper 16 bits are discarded.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

added 27 characters in body
Source Link
user6971
user6971

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification the exact behaviour is implementation-defined, meaning anything may happen (and the exact behaviour is -hopefully- documented somewhere deep down in the Arduino docs). What normally happens is that the upper 16 bits are discarded, but you can't rely on that.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like int time = millis() - 1000, you try to store that in a 16-bit integer int. A 16-bit integer can never hold a 32-bit value.

According to the C specification the exact behaviour is implementation-defined, meaning anything may happen (and the exact behaviour is -hopefully- documented somewhere deep down in the Arduino docs). What normally happens is that the upper 16 bits are discarded, but you can't rely on that.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

millis() returns a unsigned long, which is a 32-bit unsigned integer on the Arduino. When you then try to do something like unsigned int time = millis() - 1000, you try to store that in a 16-bit unsigned integer unsigned int. A 16-bit integer can never hold a 32-bit value.

According to the C specification the exact behaviour is implementation-defined, meaning anything may happen (and the exact behaviour is -hopefully- documented somewhere deep down in the Arduino docs). What normally happens is that the upper 16 bits are discarded, but you can't rely on that.

If possible, keep the millis() output in a unsigned long and only use data types with less bits when you're absolutely sure you will not lose bits.

There's more information on explicit casts in C here: http://stackoverflow.com/a/13652624/1544337

unsigned long != uint32_t
Source Link
user6971
user6971
Loading
fixed wrong typename
Source Link
BrettFolkins
  • 4.4k
  • 1
  • 14
  • 26
Loading
Post Migrated Here from electronics.stackexchange.com (revisions)
Source Link
user6971
user6971
Loading