'Why is STM32 header file using unsigned int instead of unsigned long?
Below is from a header file of a STM32 microcontroller board:
#define RCC_APB2RSTR_USART1RST_Pos (14U)
#define RCC_APB2RSTR_USART1RST_Msk (0x1UL << RCC_APB2RSTR_USART1RST_Pos) /*!< 0x00004000 */
At first line when I hover on 4U it shows it as "unsigned int"; the second line used UL which is "unsigned long".
But according to this page both "unsigned int" and "unsigned long" are same (both being 32-bit and unsigned integers ):
What could be the reason they don't follow the same types here? Why not using 14UL but 14U even though they are same?
Solution 1:[1]
See https://en.wikipedia.org/wiki/C_data_types
Although unsigned int is usually always 4 bytes (32-bit arch), the spec states it only has to be at minimum 2 bytes. Unsigned long is spec'd to be minimum of 4 bytes. When shifting like above its less likely for an overflow to happen since those are probably copy/pasted or auto generated from a script. Its also possible its a typo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David |