-
Using bool with MSVC++
Hi,
I am trying to include stdbool.h in a C program I am writing using MSVC++. I get a fatal error that it cannot open. No such file exists. I thought I needed to place it in the "stdafx.h" but that did not work either.
What is my issue here?
Thanks
-
That stdbool.h is a C99 header, and Microsoft will never support C99.
-
Thank you Salem.
Is there any way to use boolean at all...another header...anything?
Thanks
-
A couple of #defines (or an enum if you're feeling that way inclined), and any integral type work as a boolean in C.
-
Lost me.
do you mean
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
typedef int bool
-
-
That would work, though I'm unusure of what stdbool.h contains.
-
> do you mean
Yes, that's exactly it.
-
Maybe something like this would be better, in case you ever plan on updating the code to C++:
Code:
#ifndef __cplusplus
typedef int bool;
# define true 1
# define false 0
#endif
-
-
Better to use an enum. It will give you better error messages:
Code:
#ifndef __cplusplus
enum bool{
false,
true
};
#endif