Fun fact, not: In C, it's difficult to evaluate an expression in 8 bits. Integer promotion implicitly converts almost everything to int. Such as...

void f(uint8_t prev, uint8_t next) { if (next == (uint8_t) (prev + 1)) { /* cast needed to avoid promotion to int */ } }

Without casting, "prev + 1" is (at least) a 16-bit operation. The 16-bit PDP-11 was C's original platform, "int" is a reasonable default to write long expressions without casting. On 8-bit machines, like the common chips in #electronics, it can be a serious problem, slow 16-bit math can automagically appear out of nowhere. ​:woozy_baa:​

Follow

@niconiconi Isn't this technically still an at-least-16-bit operation followed by a cast to uint8 (which is equivalent to an 8bit operation on uint8 in this case)?

@robryk@qoto.org Exactly. But an explicitly cast like this is easily recognized by nearly all compilers to output 8-bit instructions, you don't need a powerful optimizer to do this transformation.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.