Tmx*_*Tmx 1 c microcontroller arm 8051
假设有
function f(int8_t a, int8_t b) // a b only need 8 bits
Run Code Online (Sandbox Code Playgroud)
另一种选择是:
function f(int32_t a, int32_t b) // a b only need 8 bits
Run Code Online (Sandbox Code Playgroud)
它运行在32位MCU,如ARM Cortex_M.哪个是关于所需代码大小,数据大小和执行效率的更好选择?
如果在8位MCU如8051,那int8_t应该更好吧?
C为您提供stdint.h了更多类型,您可以假定在编译器实现级别上回答了该问题.摘自C99草案:
7.20.1.3最快的最小宽度整数类型
1以下每种类型都指定一个通常最快的整数类型(255),以便在具有至少指定宽度的所有整数类型中进行操作.
2 typedef名称int_fastN_t指定宽度至少为N的最快有符号整数类型.typedef名称uint_fastN_t指定宽度至少为N的最快无符号整数类型.
3需要以下类型:int_fast8_t int_fast16_t int_fast32_t int_fast64_t uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
所以只要它们在您的架构中定义,只需使用int_fast8_t(或uint_fast8_t)
| 归档时间: |
|
| 查看次数: |
1049 次 |
| 最近记录: |