Data Type Definition of the Keil MDK compiler.

Source: Internet
Author: User

Data Type Definition of the Keil MDK compiler.

1 # include "usart. h "2 int main () 3 {4 usartmediaconfig (); // serial port initialization, the following information is printed through the serial port 5 printf (" char: % d \ r \ n ", sizeof (char); 6 printf ("unsigned char: % d \ r \ n", sizeof (unsigned char); 7 printf ("short: % d \ r \ n ", sizeof (short); 8 printf (" unsigned short: % d \ r \ n ", sizeof (unsigned short )); 9 printf ("int: % d \ r \ n", sizeof (int); 10 printf ("unsigned int: % d \ r \ n ", sizeof (unsigned int); 11 printf ("long: % d \ r \ n", sizeof (long); 12 printf ("unsigned long: % d \ r \ n ", sizeof (unsigned long); 13 printf (" float: % d \ r \ n ", sizeof (float )); 14 printf ("double: % d \ r \ n", sizeof (double); 15 while (1); 16}

The preceding Code defines the length of common data types in the Keil MDK compiler.

The result is as follows:

Char: 1
Unsigned char: 1
Short: 2
Unsigned short: 2
Int: 4
Unsigned int: 4
Long: 4
Unsigned long: 4
Float: 4
Double: 8




How many data types are defined by the keil compiler?

Method 1: Use the sizeof operator directly in the Code. For example, if a = sizeof (int), the value of a is the length of an int.
Method 2: After compilation is successful, open the. map File (or. m51) and find the SYMBOL.
For example:
00000036 h symbol data byte temp
00000037 h symbol data byte temp2
Temp, temp2 is the variable name, 00036H is the starting address of the variable, DATA indicates that the variable is in the data area, and BYTE indicates that the variable is in the BYTE type, that is, a BYTE. You can calculate the length by the address difference of different variables.

Does the int32_t type in the keil mdk already exist by default?

In general, keil does not contain the Type Definitions. If it is in a program compiled by someone else, maybe he has a defined type alias, maybe you did not include the response header file yourself, in fact, you can also define it by yourself, which is not very troublesome.
The advantage of doing so is that there is no need to write a long string of types each time to simplify the purpose of the program. This alias is also very nice. At first glance, we know it is a 32-bit integer, as long as you can know what he is, it's easy to change and there's no need to be too entangled!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.