Some devices have 8 bit registers, some 16 bit, some 32 bit, etc. Sometimes I write code that I want to be used on different platforms with a different number of bits.
I see two approaches to this, but I wonder which is better:
#1 - Use an "int" and let it be 32-bit on a 32-bit platform and 16-bit on a 16-bit platform. It would be wasteful on a 8-bit platform if an uint8_t could do the job.
#2 - Use whatever will hold the data, for example a small loop from 0-23 could use a uint8_t to do it. Does this create unnecessary code for 16-bit or 32-bit plaforms that have larger registers? Do they have to put in extra instructions to deal with the smaller rollover and use of the uint8_t?
I see two approaches to this, but I wonder which is better:
#1 - Use an "int" and let it be 32-bit on a 32-bit platform and 16-bit on a 16-bit platform. It would be wasteful on a 8-bit platform if an uint8_t could do the job.
#2 - Use whatever will hold the data, for example a small loop from 0-23 could use a uint8_t to do it. Does this create unnecessary code for 16-bit or 32-bit plaforms that have larger registers? Do they have to put in extra instructions to deal with the smaller rollover and use of the uint8_t?