在具有两种体系结构的嵌入式系统中使用的整数和布尔类型

我正在为嵌入式系统编写一些软件,主要是在C语言中。它恰好是双核TI平台,我使用的是一些供应商和其他库。 处理器有一个32位的ARM内核,可以进行字节访问( sizeof(char) == 1sizeof(int) == 4 :8和32位)和一个C28内核,它是一个32位CPU sizeof(char) == sizeof(int) == 1 :两者都是16位( 是的,真的 )。

我打算避免使用像intchar这样的类型来支持我总是明确我在做什么。 无论如何我会计划这个,但是当“char”有点叛逆并且不总是8位时我会加倍。

但是,我有很多整数和布尔值定义(和浮点数,但我们不用担心它们)可供我使用,具体取决于我包含的确切数量和数量:

在ARM方面:

  // from the ARM compiler's include dir typedef signed char int8_t; typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned int uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; 

在C28方面:

  // from the C28 compiler's include dir typedef int int16_t; typedef unsigned int uint16_t; typedef long int32_t; typedef unsigned long uint32_t; // note: no uint8_t 

双方:

 // "DSP28_DATA_TYPES" - comes with the following comment: // For Portability, User Is Recommended To Use Following Data Type Size // Definitions For 16-bit and 32-Bit Signed/Unsigned Integers: typedef int int16; typedef long int32; typedef long long int64; typedef unsigned long long Uint64;  // "TI_STD_TYPE", also with and xdc_ prefix, presumably for internal use to the XDC framework typedef int Int; typedef unsigned Uns; typedef char Char; typedef unsigned long Uint32; typedef unsigned int Uint16; typedef unsigned char Uint8; typedef long Int32; typedef int Int16; typedef char Int8; 

还有一些特定于库的版本,例如

 typedef char INT8; // from the NDK network headers typedef unsigned char u8_t; // from the uIP network headers 

至于布尔,我有

  // on ARM  // on C28 typedef unsigned char bool;  // on both typedef unsigned short Bool; /* boolean flag */ // TI Driver library typedef unsigned char tBoolean; // TI Flash access library typedef unsigned char boolean; 

我的直觉是两边都有 。 这将产生副作用,即我在ARM和C28核心之间共享的任何头文件都不能使用uint8_t 。 但是,这个IPC代码非常有限并且易于处理。

对于仅在一个核心上运行的代码,这意味着我不需要在这样的情况下引入TI或库头:

 // someheader_arm.h #include  // only need a standard header, not a TI one #include  extern uint8_t getDeviceFooIndex(void); extern bool isDeviceFoobared(void); 

这意味着我可以像这样包含并防止强制标头的用户首先包含一些库头,或通过将库include添加到我的标头强制它的可见性:

 // someimpl_arm.c #include "someheader_arm.h" // include first of all to ensure that all types are visible to the headers #include  // brings in UintN, for example // main.c #include "someheader_arm.h" #include  // eg needed by main.c functions // include order doesn't matter - UintN isn't needed by someheader_arm.h 

有些地方,库函数的函数签名采用unsigned long样式或UintN样式,但它总是很清楚什么是什么。 主要关注的是保持标题如上例和变量在我的代码中整齐和一致,即使我从库调用的函数使用一系列令人兴奋的定义。

事实上像charint这样的东西在两个核心上有很大的不同是一个有趣的怪癖,但我的问题甚至可以在一个核心处理器上存在,我只有比平常更多的类型!

所以问题是:将C99标准头文件作为代码中的通用标准并且通常忽略库中提供的各种类型是否有意义?