Choosing an Integer Data Type

This tip has been extracted from the full Choosing an Integer Data Type article.

The char type is not the most efficiently accessed integer type when using MPLAB XC16 or XC32, yet it is for XC8. How can you write portable code that is efficient for all device targets? Easy: Use the fastest minimum-width integer types provided by <stdint.h>, and don’t make assumptions about which type will produce the smallest or fastest code.

For example if you need a variable that can hold an 8-bit quantity, make it either of the int_fast8_t or uint_fast8_t types. If you need a variable that can hold a 16-bit quantity, use either of the int_fast16_t or uint_fast16_t types, etc. The compiler will define these types appropriately and ensure that your code is compact and runs as fast as possible, regardless of which device you are targeting.

© 2017 Microchip Technology, Inc.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.