Tool/software: Code Composer Studio
hi:
I met a problem in ccs configurate , when I want use bool type ,but show I can't , reasion is "bool" just can be use in C . not Cplusplus . where can i set this?
thanks !
best regard!
hunk
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
hi:
I met a problem in ccs configurate , when I want use bool type ,but show I can't , reasion is "bool" just can be use in C . not Cplusplus . where can i set this?
thanks !
best regard!
hunk
yanzhen fu said:reasion is "bool" just can be use in C
That is incorrect. bool is a built-in type in C++, just like int. It is not a built-in type for C. What is typically done in C is #include <stdbool.h>, then use bool just like any other type. In fact, the code you show above is from the header file <stdbool.h> . I'm not sure why you show it.
Thanks and regards,
-George
The macro __cplusplus is predefined by the compiler. If the code being compiled is C++, then this symbol is defined and has a non-zero value. Otherwise, it is not defined. At the same time, the keyword bool is not defined for C, but it is defined for C++.
So, this test from stdbool.h ...
#ifndef __cplusplus
is true when C code is being compiled, false otherwise.
How does the compiler know when the source code is C++? Under most circumstances, the file extension controls it. If the file extension is .cpp, then the code is C++. If the file extension is .c, then the code is C.
Thus, when C code is being compiled, that code in stdbool.h creates a definition for bool that can be used in C code. When C++ code is being compiled, that code does nothing.
Thanks and regards,
-George
If this is C code, and you #include <stdbool.h>, then I don't know why you would have an error. If that is what you experience, then I need a test case which allows me to reproduce the same behavior. Please submit one as described in How to Submit a Compiler Test Case.
Thanks and regards,
-George
I tried to make it clear that, to use bool in C code, you have to use this header file
#include <stdbool.h>
The source file you sent doesn't. When I add it, it builds clean.
Thanks and regards,
-George