|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求大佬指点 谢谢啦
代码如下:
printf("_Bool = %d\n",sizeof(_Bool));
错误信息如下:
[Error] '_Bool' was not declared in this scope
这是C语言,这么写的前提是有一行这样的代码
- $ cat main.c
- #include <stdio.h>
- int main(void) {
- printf("_Bool = %d\n",sizeof(bool));
- return 0;
- }
- $ gcc --version
- gcc (GCC) 11.1.0
- Copyright (C) 2021 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- $ gcc -g -Wall -o main main.c
- main.c: In function ‘main’:
- main.c:4:34: error: ‘bool’ undeclared (first use in this function)
- 4 | printf("_Bool = %d\n",sizeof(bool));
- | ^~~~
- main.c:2:1: note: ‘bool’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’?
- 1 | #include <stdio.h>
- +++ |+#include <stdbool.h>
- 2 |
- main.c:4:34: note: each undeclared identifier is reported only once for each function it appears in
- 4 | printf("_Bool = %d\n",sizeof(bool));
- | ^~~~
- $
复制代码
- $ cat main.c
- #include <stdio.h>
- #include <stdbool.h>
- int main(void) {
- printf("_Bool = %d\n",sizeof(bool));
- return 0;
- }
- $ gcc -g -Wall -o main main.c
- main.c: In function ‘main’:
- main.c:5:22: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat ]
- 5 | printf("_Bool = %d\n",sizeof(bool));
- | ~^ ~~~~~~~~~~~~
- | | |
- | int long unsigned int
- | %ld
- $ ./main
- _Bool = 1
- $
复制代码
应该这样才正确
- $ cat main.c
- #include <stdio.h>
- #include <stdbool.h>
- int main(void) {
- //printf("_Bool = %d\n",sizeof(bool));
- printf("_Bool = %lu\n",sizeof(bool));
- return 0;
- }
- $ gcc -g -Wall -o main main.c
- $ ./main
- _Bool = 1
- $
复制代码
|
|