请问如果在 ANSI C 中忘记常量(字面值)后缀(后缀)会发生什么?
例如,我看到位移操作的定义如下:
#define AAR_INTENSET_NOTRESOLVED_Pos (2UL) /*!< Position of NOTRESOLVED field. */
#define AAR_INTENSET_NOTRESOLVED_Msk (0x1UL << AAR_INTENSET_NOTRESOLVED_Pos) /*!< Bit mask of NOTRESOLVED field. */
#define AAR_INTENSET_NOTRESOLVED_Disabled (0UL) /*!< Interrupt disabled. */
#define AAR_INTENSET_NOTRESOLVED_Enabled (1UL) /*!< Interrupt enabled. */
#define AAR_INTENSET_NOTRESOLVED_Set (1UL) /*!< Enable interrupt on write. */
它被用在32位架构中,但也可以移植到16位或8位架构。
如果不使用后缀UL,而是按照预期使用这些宏进行位移操作,会发生什么情况呢?
我只是假设在8位架构中,(1<<30)可能导致溢出。
编辑: 我找到了一个好网站: http://dystopiancode.blogspot.cz/2012/08/constant-suffixes-and-prefixes-in-ansi-c.html
但是如果代码要移植到各种不同的架构上,使用后缀是否安全呢?
例如,如果后缀U代表无符号整数,则对于8位架构来说,通常是16位,但对于32位来说,则是32位变量,因此0xFFFFAAAAU对于32位编译器来说是可以的,但对于8位编译器则不行,是吗?