Is FALSE == 0?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tatu Portin

    #1

    Is FALSE == 0?

    Is FALSE == 0?
    In other words, does 'function ()' execute on all platforms:

    if ( (1 == 2) == 0 )
    function ();

    if ( (7!) == 0 )
    function ();

    I would like if you could point to some definition of the c language.
  • Trent Buck

    #2
    Re: Is FALSE == 0?

    Quoth Tatu Portin on or about 2004-11-20:[color=blue]
    > Is FALSE == 0?
    > In other words, does 'function ()' execute on all platforms:[/color]

    I asked a similar question recently. Here's the google archive


    -trent

    Comment

    • Tatu Portin

      #3
      Re: Is FALSE == 0?

      Trent Buck wrote:[color=blue]
      > Quoth Tatu Portin on or about 2004-11-20:
      >[color=green]
      >>Is FALSE == 0?
      >>In other words, does 'function ()' execute on all platforms:[/color]
      >
      >
      > I asked a similar question recently. Here's the google archive
      > http://www.google.com/groups?selm=cn...s.uwaterloo.ca
      >
      > -trent[/color]

      From
      http://www.google.com/groups?selm=cn...s.uwaterloo.ca[color=blue]
      >All operators that return a boolean result are defined to return 0 or
      >1, so you can do this, or at least could if you didn't mind inverting
      >the result.[/color]

      "Are defined to return 0 or 1", but does not say whetever 0 is false or not.
      Also, I would like if one could point some place in standard (C89, C99) where
      it defines these values.

      Comment

      • Goran Larsson

        #4
        Re: Is FALSE == 0?

        In article <3hHnd.126$q93. 62@read3.inet.f i>,
        Tatu Portin <axel86@mbnet.f i> wrote:
        [color=blue]
        > Is FALSE == 0?[/color]

        Yes.
        [color=blue]
        > if ( (1 == 2) == 0 )
        > function ();[/color]

        Yes.
        [color=blue]
        > if ( (7!) == 0 )
        > function ();[/color]

        No, this will not compile.

        | if ( (!7) == 0 )
        | function ();

        Yes.
        [color=blue]
        > I would like if you could point to some definition of the c language.[/color]

        The ANSI/ISO/IEC 9899-1999 standard.

        --
        Göran Larsson http://www.mitt-eget.com/

        Comment

        • Tatu Portin

          #5
          Re: Is FALSE == 0?

          Goran Larsson wrote:[color=blue]
          > In article <3hHnd.126$q93. 62@read3.inet.f i>,
          > Tatu Portin <axel86@mbnet.f i> wrote:
          >[color=green]
          >>Is FALSE == 0?[/color]
          >
          > Yes.
          >[color=green]
          >>if ( (1 == 2) == 0 )
          >> function ();[/color]
          >
          > Yes.
          >[color=green]
          >>if ( (7!) == 0 )
          >> function ();[/color]
          >
          > No, this will not compile.
          >
          > | if ( (!7) == 0 )
          > | function ();
          >
          > Yes.
          >[color=green]
          >>I would like if you could point to some definition of the c language.[/color]
          >
          > The ANSI/ISO/IEC 9899-1999 standard.
          >[/color]

          Thanks. Just if you could give some www-adress for reference.

          Comment

          • Michael Mair

            #6
            Re: Is FALSE == 0?

            Tatu Portin wrote:
            [color=blue]
            > Goran Larsson wrote:
            >[color=green]
            >> Tatu Portin <axel86@mbnet.f i> wrote:[color=darkred]
            >>> I would like if you could point to some definition of the c
            >>> language.[/color]
            >>
            >> The ANSI/ISO/IEC 9899-1999 standard.[/color]
            >
            > Thanks. Just if you could give some www-adress for reference.[/color]

            The standard is available for about 270 USD as paper copy or from
            webstore.ansi.o rg for 18 USD as .pdf file.
            (
            http://webstore.ansi.org/ansidocstor...EC+9899%2D1999
            )

            For most beginners, N869, the last public (and freely available) draft
            is quite enough. Use google to obtain it.

            Cheers
            Michael
            --
            E-Mail: Mine is an /at/ gmx /dot/ de address.

            Comment

            • Minti

              #7
              Re: Is FALSE == 0?

              Tatu Portin wrote:[color=blue]
              > Goran Larsson wrote:
              >[color=green]
              >> In article <3hHnd.126$q93. 62@read3.inet.f i>,
              >> Tatu Portin <axel86@mbnet.f i> wrote:
              >>[color=darkred]
              >>> Is FALSE == 0?[/color]
              >>
              >>
              >> Yes.
              >>[color=darkred]
              >>> if ( (1 == 2) == 0 )
              >>> function ();[/color]
              >>
              >>
              >> Yes.
              >>[color=darkred]
              >>> if ( (7!) == 0 )
              >>> function ();[/color]
              >>
              >>
              >> No, this will not compile.
              >>
              >> | if ( (!7) == 0 )
              >> | function ();
              >>
              >> Yes.
              >>[color=darkred]
              >>> I would like if you could point to some definition of the c language.[/color]
              >>
              >>
              >> The ANSI/ISO/IEC 9899-1999 standard.
              >>[/color]
              >
              > Thanks. Just if you could give some www-adress for reference.[/color]


              I believe your c-book whichever it is should be able to answer this
              question.


              If it does not maybe you need another book.

              --
              Imanpreet Singh Arora

              Comment

              • Keith Thompson

                #8
                Re: Is FALSE == 0?

                Michael Mair <Michael.Mair@i nvalid.invalid> writes:
                [...][color=blue]
                > The standard is available for about 270 USD as paper copy or from
                > webstore.ansi.o rg for 18 USD as .pdf file.
                > (
                > http://webstore.ansi.org/ansidocstor...EC+9899%2D1999
                > )
                >
                > For most beginners, N869, the last public (and freely available) draft
                > is quite enough. Use google to obtain it.[/color]

                For most beginners, a good book is going to be much more useful than a
                copy of the standard. K&R2 is one of the best (_The C Programming
                Language_, 2nd Edition, by Kernighan & Ritchie).

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • Keith Thompson

                  #9
                  Re: Is FALSE == 0?

                  Tatu Portin <axel86@mbnet.f i> writes:[color=blue]
                  > Is FALSE == 0?
                  > In other words, does 'function ()' execute on all platforms:
                  >
                  > if ( (1 == 2) == 0 )
                  > function ();
                  >
                  > if ( (7!) == 0 )
                  > function ();
                  >
                  > I would like if you could point to some definition of the c language.[/color]

                  Read section 9 of the C FAQ, <http://www.eskimo.com/~scs/C-faq/top.html>.
                  (If you forget the URL, just google "C FAQ".)

                  --
                  Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                  San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                  We must do something. This is something. Therefore, we must do this.

                  Comment

                  • Michael Mair

                    #10
                    Re: Is FALSE == 0?

                    Hi Keith,

                    Keith Thompson wrote:
                    [color=blue]
                    > Michael Mair <Michael.Mair@i nvalid.invalid> writes:
                    > [...]
                    >[color=green]
                    >>The standard is available for about 270 USD as paper copy or from
                    >>webstore.ansi .org for 18 USD as .pdf file.
                    >>(
                    >>http://webstore.ansi.org/ansidocstor...EC+9899%2D1999
                    >>)
                    >>
                    >>For most beginners, N869, the last public (and freely available) draft
                    >>is quite enough. Use google to obtain it.[/color]
                    >
                    > For most beginners, a good book is going to be much more useful than a
                    > copy of the standard. K&R2 is one of the best (_The C Programming
                    > Language_, 2nd Edition, by Kernighan & Ritchie).[/color]

                    Mind the "quite" :-)
                    The OP asked for the standard, I gave the answer.
                    He can have a look at N869 and see and believe that going back to
                    "ordinary" C books might be a better idea. Sometimes, you have to
                    do it for yourself...
                    Apart from K&R2, I also always refer the people to the c.l.c FAQ.


                    Cheers
                    Michael
                    --
                    E-Mail: Mine is an /at/ gmx /dot/ de address.

                    Comment

                    • Old Wolf

                      #11
                      Re: Is FALSE == 0?

                      Tatu Portin <axel86@mbnet.f i> wrote:[color=blue]
                      > Trent Buck wrote:[color=green]
                      > > Quoth Tatu Portin on or about 2004-11-20:
                      > >[color=darkred]
                      > >>Is FALSE == 0?
                      > >>In other words, does 'function ()' execute on all platforms:[/color]
                      > >All operators that return a boolean result are defined to return 0 or
                      > >1, so you can do this, or at least could if you didn't mind inverting
                      > >the result.[/color]
                      >
                      > "Are defined to return 0 or 1", but does not say whetever 0 is false or not.[/color]

                      FALSE and false are not part of C. So please rephrase
                      your question.
                      [color=blue]
                      > Also, I would like if one could point some place in standard
                      >(C89, C99) where it defines these values.[/color]

                      FALSE is not defined anywhere. The section on operators says what
                      the result of each operator is.

                      Comment

                      • Mark McIntyre

                        #12
                        Re: Is FALSE == 0?

                        On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , oldwolf@inspire .net.nz (Old
                        Wolf) wrote:
                        [color=blue]
                        >FALSE and false are not part of C. So please rephrase
                        >your question.[/color]

                        Incorrect.

                        false is a macro defined as zero in stdbool.h

                        Note however this final sentence:
                        "Notwithstandin g the provisions of 7.1.3, a program may undefine and
                        perhaps then redefine the macros bool, true, and false"


                        --
                        Mark McIntyre
                        CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                        CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

                        ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                        http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                        ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

                        Comment

                        • Tatu Portin

                          #13
                          Re: Is FALSE == 0?

                          Mark McIntyre wrote:[color=blue]
                          > On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , oldwolf@inspire .net.nz (Old
                          > Wolf) wrote:
                          >
                          >[color=green]
                          >>FALSE and false are not part of C. So please rephrase
                          >>your question.[/color]
                          >
                          >
                          > Incorrect.
                          >
                          > false is a macro defined as zero in stdbool.h
                          >
                          > Note however this final sentence:
                          > "Notwithstandin g the provisions of 7.1.3, a program may undefine and
                          > perhaps then redefine the macros bool, true, and false"
                          >
                          >[/color]

                          Well, I meant that false in general. Like: Is ((1 == 2) == 0)?

                          Comment

                          • Mark McIntyre

                            #14
                            Re: Is FALSE == 0?

                            On Sun, 21 Nov 2004 13:34:33 GMT, in comp.lang.c , Tatu Portin
                            <axel86@mbnet.f i> wrote:
                            [color=blue]
                            >
                            >Well, I meant that false in general. Like: Is ((1 == 2) == 0)?[/color]

                            That remark makes no sense.... you need some context for it.

                            Anyhoo...

                            The effect of the equality operator is an int with value either one or zero
                            as appropriate (6.5.9(4)). The macros true and false are defined suitably
                            (7.16).

                            What more do you need to know?




                            --
                            Mark McIntyre
                            CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
                            CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

                            ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
                            http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
                            ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

                            Comment

                            • Keith Thompson

                              #15
                              Re: Is FALSE == 0?

                              Tatu Portin <axel86@mbnet.f i> writes:[color=blue]
                              > Mark McIntyre wrote:[color=green]
                              >> On 20 Nov 2004 21:10:57 -0800, in comp.lang.c , oldwolf@inspire .net.nz (Old
                              >> Wolf) wrote:
                              >>[color=darkred]
                              >>>FALSE and false are not part of C. So please rephrase
                              >>>your question.[/color]
                              >> Incorrect. false is a macro defined as zero in stdbool.h Note
                              >> however this final sentence:
                              >> "Notwithstandin g the provisions of 7.1.3, a program may undefine and
                              >> perhaps then redefine the macros bool, true, and false"[/color][/color]

                              This is a new feature in C99.
                              [color=blue]
                              > Well, I meant that false in general. Like: Is ((1 == 2) == 0)?[/color]

                              The relational operators yield either 0 (for false) or 1 (for true),
                              as do the "&&", "||", and "!" operators.

                              A function that returns a value to be used as a condition (e.g., in an
                              if statement) must return 0 for false, but may return any non-zero
                              value for true. This includes functions like isdigit() declared in
                              the standard header <ctype.h>.

                              The language *could* have been defined so that the relational
                              operators may yield any non-zero result when the condition is true,
                              but they were restricted to 0 and 1 for consistency. As a matter of
                              style, I don't recommend depending on this.

                              Whenever you test a value that represents a logical (boolean) result,
                              assume that any non-zero value can be used to represent truth. For
                              example, suppose you have a function

                              int argument_is_val id(some_type argument);

                              and suppose you've defined

                              #define FALSE 0
                              #define TRUE 1

                              This is ok:

                              if (argument_is_va lid(foo)) { ... }

                              This is needlessly verbose:

                              if (argument_is_va lid(bar) == FALSE) { ... }

                              And this is dangerous:

                              if (argument_is_va lid(baz) == TRUE ) { ... }

                              because the function could return 2 to indicate that the argument is
                              valid.

                              But using "return TRUE;" or "return FALSE;" in the body of the
                              function is just fine.

                              Never compare a boolean value against TRUE or FALSE.

                              (C99 changes this a bit by introducing a predefined type _Bool or
                              bool, and predefined values true and false.)

                              --
                              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                              San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                              We must do something. This is something. Therefore, we must do this.

                              Comment

                              Working...