Bool

T

Terry Andersen

Why do my compiler error about:

parse error before `check_arrays' when executing this piece of code:

bool check_arrays(unsigned char* in_array){
if((global_IP[0] == *(in_array)) && (global_IP[1] == *(in_array+1)) &&
(global_IP[2] == *(in_array+2)) && (global_IP[3] == *(in_array+3))){
return true;
}
else{return false;}
}


Do I need some includes to use the "bool"???

Best Regards
Terry
 
D

Darrell Grainger

Terry Andersen a écrit:

yes

#include <stdbool.h>

This only holds true for C99 compilers. The older compilers do not have a
stdbool.h header. For older compilers you will have to create your own
defines or see if the compiler has implemented a header similar to the
stdbool.h header.
 
S

Serve La

Jan Engelhardt said:
What is the deal with bool, anyway? It is just a char (at least! it might be
an int.)

Just a way to express what you mean.
"char x(int)" is less obvious than "bool x(int)". Nonetheless I never use
bool in C. (although my compiler has the header) Because it's a macro it
does break a lot of existing code
 
S

Serve La

Serve La said:
Just a way to express what you mean.
"char x(int)" is less obvious than "bool x(int)". Nonetheless I never use
bool in C. (although my compiler has the header) Because it's a macro it
does break a lot of existing code

ah, drop the "because it's a macro" part
 
T

those who know me have no need of my name

in comp.lang.c i read:
What is the deal with bool, anyway? It is just a char (at least! it might
be an int.)

not in c99 it isn't if <stdbool.h> has been included. in c99 a bool (aka a
_Bool) can have only two values, 0 or 1.
 
C

CBFalconer

Darrell said:
This only holds true for C99 compilers. The older compilers do
not have a stdbool.h header. For older compilers you will have to
create your own defines or see if the compiler has implemented a
header similar to the stdbool.h header.

I simply #include "stdops.h", which is the following:

/* Standard defines of operators, usable on C90 up */
#ifndef stdops_h
#define stdops_h
#if defined(__STDC__) && (__STDC_VERSION__ >= 199901L)
/* The following from C99 - must define for C90 */
#include <stdbool.h> /* define bool, true, false */
#include <iso646.h> /* define not, and, or, xor */
#else
#define false 0
#define true 1
typedef int bool;
#define not !
#define and &&
#define or ||
#define xor ^
#endif
#endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top