3 ms·
Choose the right tool for the job. Examples: - Loop using an iterator: unsigned pointer size - Array index: unsigned pointer size - Enum used to represen
by the__alchemist 5y ago
Choose the right tool for the job. Examples:
- Loop using an iterator: unsigned pointer size
- Array index: unsigned pointer size
- Enum used to represent a register value that's 8 bits or less: unsigned 8 bit
- ... used to represent a register value that's up to 16 or 32 bits: unsigned 16 or 32 bit number
- Integer value that could be negative: Signed, with the appropriate size
- Doing numerical operations and you have an FPU: Float. Unless you're careful, you know what you're doing, and it's either performance critical or you're using dedicated a dedicated fixed-pointer hardware peiph... then maybe fixed point with a signed or unsigned integer.
- Analog value that can only be positive; maybe a voltage: unsigned integer according to precision of the ADC etc
- Analog value that can be positive or negative; maybe pH, audio, or something using a differential ADC: signed integer
- Performing mathematical operations including subtraction, don't expect fixed-point errors to come up, and you don't want to use floating point or don't have an FPU: signed integer