您使用的語法錯誤。如下使用它。
#include <stdio.h>
enum bool // if *typedef enum* is used instead, it's working fine
{
_false,
_true,
} ;
enum bool func1(enum bool);
int main()
{
printf("Return Value = %d\n\n", func1(_true));
return 0;
}
enum bool func1(enum bool status)
{
return status;
}
相反,如果你使用的typedef就可以直接使用bool
代替enum bool
。
還引述C99標準:
Section 7.16 Boolean type and values <stdbool.h>
1 The header <stdbool.h> defines four macros.
2 The macro
bool expands to _Bool.
3 The remaining three macros are suitable for use in #if preprocessing directives. They are
true : which expands to the integer constant 1,
false: which expands to the integer constant 0, and
__bool_true_false_are_defined which expands to the integer constant 1.
4 Notwithstanding the provisions of 7.1.3, a program may undefine and perhaps then redefine the macros bool, true, and false.
如果你有編譯器來編譯,以C99標準,那麼你可以只包括stdbool.h
和使用布爾像bool b = true;
。
只需提及在C99中引入的''。 –
hmjd