Here comes the boss:

Sugar sugar guy, you engage in C language embedded development for so long, I come to test you U8, U16, U32, S8, S16, S32 what do you mean? If I am satisfied with your answer, I will give you a promotion and a raise, and you will be on the top of your life from now on

Report to boss:

As the king of C backdoor development, err… wrong. Pooh, pooh, pooh, C language embedded development of the emperor, this small problem how can be baffled by this handsome than?

Let’s cut to the chase and not panic:

U8 is unsigned char, u16 is unsigned short, and U32 is unsigned long. S8 is signed char, S16 is signed short, and S32 is signed long.

It’s time for a wave of strength:

  • Obviously, u means unsigned, s means signed, 8 means eight bits (one byte), 16 means 16 bits (two bytes), and 32 means 32 bits (four bytes).
  • The purpose of this writing is to improve cross-platform portability and compatibility. Different platforms have different data type definitions. To be compatible with different platforms, a set of code must have the same data type to prevent ambiguity (for example, int occupies 4 bytes in VC6.0, but 2 bytes in Turbo C2.0. U16 provides a unified definition to ensure cross-platform portability; In addition, VC long int and int is no difference, both types of 4 bytes to store data).
  • Using typedef keywords to alias variables makes coding easier. This is a simple, clear way to write, and we will use it a lot in standard header files as well as in future programming practices.

Appendix Integer data types:

Note that super-long and unsigned super-long integers were introduced in C++11.

Is the long type 4 bytes or 8 bytes

Long is 8 bytes in a Linux 64-bit gCC9.1 compiler environment. Alas, I can only say that it is a case-by-case case, and some types are different in different debugging environments (32-bit vs. Win64, long is 4 bytes; **sizeof()** sizeof()**

#include <iostream>
using namespace std;
int main(a) {
    cout << "char size is:" << sizeof(char) << endl;
    cout << "short size is:" << sizeof(short) << endl;
    cout << "int size is:" << sizeof(int) << endl;
    cout << "long size is:" << sizeof(long) << endl;
    cout << "long long size is:" << sizeof(long long) << endl;
}
Copy the code

The last example:

Stdint. H file:

 /* TYPE DEFINITIONS */
typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
Copy the code

Stm32f10x.h file:

/ *! < STM32F10x Standard Peripheral Library old types (maintained for legacy purpose) */
typedef int32_t  s32;
typedef int16_t s16;
typedef int8_t  s8;
typedef const int32_t sc32;  / *! < Read Only */
typedef const int16_t sc16;  / *! < Read Only */
typedef const int8_t sc8;   / *! < Read Only */
typedef __IO int32_t  vs32;
typedef __IO int16_t  vs16;
typedef __IO int8_t   vs8;
typedef __I int32_t vsc32;  / *! < Read Only */
typedef __I int16_t vsc16;  / *! < Read Only */
typedef __I int8_t vsc8;   / *! < Read Only */
typedef uint32_t  u32;
typedef uint16_t u16;
typedef uint8_t  u8;
typedef const uint32_t uc32;  / *! < Read Only */
typedef const uint16_t uc16;  / *! < Read Only */
typedef const uint8_t uc8;   / *! < Read Only */
typedef __IO uint32_t  vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t  vu8;
typedef __I uint32_t vuc32;  / *! < Read Only */
typedef __I uint16_t vuc16;  / *! < Read Only */
typedef __I uint8_t vuc8;   / *! < Read Only */
Copy the code

Examples of header files used:

#ifndef _MINTS_TYPE_H_
#define _MINTS_TYPE_H_

#ifndef _MSC_VER
#include <stdint.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Type definition */
/*-----------------------------------------------------------------------------
System public files are strictly prohibited to modify
------------------------------------------------------------------------------*/

/* windows visual studio compiler */
#if defined(_MSC_VER)
typedef signed char     s8;
typedef unsigned char   u8;
typedef signed short    s16;
typedef unsigned short  u16;
typedef signed int      s32;
typedef unsigned int    u32;
typedef __int64         s64;
typedef unsigned __int64 u64;

/* gcc, xcoder, intel or other C99 support compiler */
#else   
typedef int8_t          s8;
typedef uint8_t         u8;
typedef int16_t         s16;
typedef uint16_t        u16;
typedef int32_t         s32;
typedef uint32_t        u32;
typedef int64_t         s64;
typedef uint64_t        u64;

#endif //_MSC_VER

#ifdef __cplusplus
}
#endif  /* __cplusplus */

#endif /* _MINTS_TYPE_H_ */
Copy the code

From the scriptures:

C.biancheng.net/cpp/html/10… C.biancheng.net/view/1318.h… www.cplusplus.com/reference/c… www.keil.com/dd/docs/arm… www.qnx.com/developers/…

The end of the message

That concludes our introduction to embedded data types. I’ll see you in the next post

It is not easy to write a blog, such as being loved, appreciate a concern, one key three connect ~~ like + comment + collection 🤞🤞🤞, thank you for your support ~~Copy the code