New types of C99 syntax _bool

Source: Internet
Author: User

The new Boolean type syntax for _bool is added in the C99 syntax, as shown in the following example:

1#include <stdio.h>2#include <stdlib.h>3 4 intMainintargcChar**argv)5 {6 _bool B;7b =0;8printf"%d\n", b);9b =1;Tenprintf"%d\n", b); Oneb =3; Aprintf"%d\n", b); -b =4; -printf"%d\n", b); theprintf"%d\n",sizeof(b)); -  -printf"%d\n", b); - GetChar (); +     return 0; -}

The results are as follows:

The disassembly results are as follows:

_bool B; b=0; 0119406E movbyteptr [b],0printf ("%d\n", b);01194072movzx eax,byteptr [b]01194076mov esi,esp01194078push EAX01194079Push 1195858h 0119407E call DWORD ptr ds:[1199110h]01194084Add ESP,8  01194087CMP Esi,esp01194089Call __rtc_checkesp (01191136h) b=1; 0119408E movbyteptr [b],1printf ("%d\n", b);01194092movzx eax,byteptr [b] printf ("%d\n", b);01194096mov esi,esp01194098push EAX01194099Push 1195858h 0119409E call DWORD ptr ds:[1199110h] 011940a4 add ESP,8011940A7 cmp esi,esp 011940a9 call __RTC_CHECKESP (01191136h) b=3; 011940AE mov eax,3011940b3 Test eax,eax 011940b5 jne main+73h (011940C3H) 011940b7 mov dword ptr [EBP-0D0H],0011940C1 jmp Main+7Dh (011940CDh) 011940C3 mov dword ptr [EBP-0D0H],1011940CD mov cl,bytePTR [ebp-0d0h] 011940D3 movbyteptr [b],cl printf ("%d\n", b); 011940d6 movzx eax,byteptr [b] 011940DA mov esi,esp 011940DC push eax printf ("%d\n", b); 011940DD push 1195858h 011940E2 call DWORD ptr ds:[1199110h] 011940E8 add ESP,8011940EB cmp esi,esp 011940ED call __RTC_CHECKESP (01191136h) b=4; 011940F2 mov eax,4011940f7 Test eax,eax 011940f9 jne main+0b7h (01194107h) 011940FB mov dword ptr [EBP-0D0H],0  01194105JMP main+0c1h (01194111h)01194107mov dword ptr [ebp-0d0h],1  01194111MOV cl,bytePTR [ebp-0d0h]01194117movbyteptr [b],cl printf ("%d\n", b); 0119411A movzx eax,byteptr [b] 0119411E mov esi,esp01194120push EAX01194121Push 1195858h01194126Call dword ptr ds:[1199110h] 0119412C add ESP,80119412F CMP Esi,esp01194131Call __rtc_checkesp (01191136h) printf ("%d\n",sizeof(b));01194136mov esi,esp01194138Push10119413A push 1195858h 0119413F call DWORD ptr ds:[1199110h]01194145Add ESP,8  01194148CMP esi,esp 0119414A call __RTC_CHECKESP (01191136h)

As can be seen from the results, not 0 is 1;

The results from the disassembly can also be seen

    4 ; 011940f2  mov         eax,4  011940f7  test        eax,eax  011940f9  jne         main+0b7h (01194107h)  011940FB  mov         dword ptr [EBP-0d0h],0  01194105  JMP         main+0c1h (01194111h)  01194107  mov         dword ptr [ebp-0d0h],1   01194111  mov         cl,byte ptr [ebp-0d0h]  01194117   mov         byte ptr [b],cl  

b = 4

MOV eax,4

The Prime Minister 4 gave eax;

Test Eax,eax

As long as it's not 0, it's 1.

This is the internal mechanism of the _bool type.

By:ecn14

New types of C99 syntax _bool

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.