I'm pretty sure this is again something about C99, but how do I use booleans in C code in Visual Studio 2010?
Printable View
I'm pretty sure this is again something about C99, but how do I use booleans in C code in Visual Studio 2010?
typedef int bool;
Or something similar.
Why not just
typedef char bool;
?
Why use 4 bytes (possibly) when only 1 is required? I never understood why int is used for bools.
It gives me
IntelliSense: invalid combination of type specifiers
error C2065: 'false' : undeclared identifier
error C2065: 'true' : undeclared identifier
What I find strange is that it has "bool", "true" and "false" all blue, ie. it understands those are keywords, but doesn't know how to use them.
That's because they are keywords in C++. But they are not for C, so you have to define them.
Something like
Code:#ifndef __cplusplus
#define TRUE 1
#define FALSE 0
#endif
If you were using some C99 compliant compiler you could use the framework for booleans in stdbool.h . Sadly though, that is not the case with VS.
If you were using C++ as a better C, you wouldn't have to deal with the problems either. Or even better if you actually used C++.
But *shrug*. MS has declared that there just aren't enough C customers to warrant implementing C99.
o_O
But then again, Visual Studio's C compiler doesn't for for embedded systems, does it?
It can run on Windows, yes, but the huge reason why I use VS2010 here is
1) I happen to have VS2010
2) The thing that I'm trying to do here is to just learn the C as well as possible
One question, or thing that I'm looking reassurance for, is that if I use this "original C" that VS2010 uses, can I assume anything that can run C99 can run this "original" C as well just "as is"?
No, you cannot. C99 is not entirely backwards compatible with C90.
The only thing that springs to mind, however, is the implicit return type. It's deprecated in C90 and disallowed in C99.