Bool

Discussion in 'C Programming' started by Terry Andersen, Aug 18, 2003.

  1. 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
    Terry Andersen, Aug 18, 2003
    #1
    1. Advertising

  2. Terry Andersen

    Marc Lasson Guest

    Terry Andersen a écrit:
    > Why do my compiler error about:

    <snip>

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

    yes

    #include <stdbool.h>

    --
    Marc.
    Marc Lasson, Aug 18, 2003
    #2
    1. Advertising

  3. On Mon, 18 Aug 2003, Marc Lasson wrote:

    > Terry Andersen a écrit:
    > > Why do my compiler error about:

    > <snip>
    >
    > > Do I need some includes to use the "bool"???

    > 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.

    > --
    > Marc.
    >
    >


    --
    main(){int j=1234;char t[]=":mad:abcdefghijklmnopqrstuvwxyz.\n",*i=
    "iqgbgxmdbjlgdv.lksrqek.n";char *strchr(const char *,int);while(
    *i){j+=strchr(t,*i++)-t;j%=sizeof t-1;putchar(t[j]);} return 0;}
    Darrell Grainger, Aug 18, 2003
    #3
  4. Terry Andersen

    Serve La Guest

    "Jan Engelhardt" <> wrote in message
    news:p...
    > >> > Why do my compiler error about:
    > >> > Do I need some includes to use the "bool"???
    > >> 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.

    >
    > 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
    Serve La, Aug 18, 2003
    #4
  5. Terry Andersen

    Serve La Guest

    "Serve La" <> wrote in message
    news:bhquvn$uni$1.nb.home.nl...
    > 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
    Serve La, Aug 18, 2003
    #5
  6. 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.

    --
    a signature
    those who know me have no need of my name, Aug 18, 2003
    #6
  7. Terry Andersen

    CBFalconer Guest

    Darrell Grainger wrote:
    > On Mon, 18 Aug 2003, Marc Lasson wrote:
    > > Terry Andersen a écrit:

    >
    > > > Why do my compiler error about:

    > > <snip>
    > >
    > > > Do I need some includes to use the "bool"???

    > > 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.


    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


    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
    CBFalconer, Aug 20, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Weng Tianxiang
    Replies:
    2
    Views:
    458
    Weng Tianxiang
    Jun 21, 2005
  2. Ignacio Machin

    Re: Convert DataRow content to bool

    Ignacio Machin, Jul 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    365
    Ignacio Machin
    Jul 7, 2003
  3. Eliyahu Goldin

    Re: Convert DataRow content to bool

    Eliyahu Goldin, Jul 7, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    350
    Eliyahu Goldin
    Jul 7, 2003
  4. Georg Mayer
    Replies:
    1
    Views:
    321
    cosine... zero
    Jun 23, 2004
  5. Patrick Olurotimi Ige

    Cannot implicitly convert type 'object' to 'bool' Error

    Patrick Olurotimi Ige, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    12,182
    Patrick Olurotimi Ige
    Jan 25, 2005
Loading...

Share This Page