Is 0 a decimal integer?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven T. Hatton

    Is 0 a decimal integer?

    I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do agree
    with me, then what do you think it is?
    --
    If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true.-Bertrand Russell
  • benben

    #2
    Re: Is 0 a decimal integer?

    Doesn't 0 mathematically mean 0 (zero, null, nil) in decimal, binary,
    hexadecimal, etc whatever number system you can devise?

    Ben


    Comment

    • Steven T. Hatton

      #3
      Re: Is 0 a decimal integer?

      benben wrote:
      [color=blue]
      > Doesn't 0 mathematically mean 0 (zero, null, nil) in decimal, binary,
      > hexadecimal, etc whatever number system you can devise?
      >
      > Ben[/color]

      I'm speaking strictly in lexical terms. How would a C++ grammarian classify
      0? I believe you are correct regarding semantics.

      --
      If our hypothesis is about anything and not about some one or more
      particular things, then our deductions constitute mathematics. Thus
      mathematics may be defined as the subject in which we never know what we
      are talking about, nor whether what we are saying is true.-Bertrand Russell

      Comment

      • Ron Natalie

        #4
        Re: Is 0 a decimal integer?

        Steven T. Hatton wrote:[color=blue]
        > I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do agree
        > with me, then what do you think it is?[/color]

        A naked 0 is a octal-literal according to the C++ standard.
        A decimimal literal is a single non-zero digit followed
        by zero or more digits.

        Comment

        • Steven T. Hatton

          #5
          Re: Is 0 a decimal integer?

          Ron Natalie wrote:
          [color=blue]
          > Steven T. Hatton wrote:[color=green]
          >> I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do
          >> agree with me, then what do you think it is?[/color]
          >
          > A naked 0 is a octal-literal according to the C++ standard.
          > A decimimal literal is a single non-zero digit followed
          > by zero or more digits.[/color]

          It's probably a completely pointless observation, but that's also how I
          understood ยง2.13.1.
          --
          If our hypothesis is about anything and not about some one or more
          particular things, then our deductions constitute mathematics. Thus
          mathematics may be defined as the subject in which we never know what we
          are talking about, nor whether what we are saying is true.-Bertrand Russell

          Comment

          • M.Pfeifer

            #6
            Re: Is 0 a decimal integer?


            "Steven T. Hatton" <chattengau@ger mania.sup> schrieb im Newsbeitrag
            news:lK6dnReX1N SZvH_fRVn-gg@speakeasy.ne t...[color=blue]
            > benben wrote:
            >[color=green]
            > > Doesn't 0 mathematically mean 0 (zero, null, nil) in decimal, binary,
            > > hexadecimal, etc whatever number system you can devise?
            > >
            > > Ben[/color]
            >
            > I'm speaking strictly in lexical terms. How would a C++ grammarian[/color]
            classify[color=blue]
            > 0? I believe you are correct regarding semantics.
            >[/color]

            You have to use a type qualifier. So it depends on you.

            I think

            (char) 0

            would be valid as well. But I didn't check it.

            Matthias


            Comment

            • Starfox

              #7
              Re: Is 0 a decimal integer?

              As much as I think this is pointless, this might solve the argument,
              sort of:

              std::cout << typeid(0).name( );

              Comment

              • Steven T. Hatton

                #8
                Re: Is 0 a decimal integer?

                Starfox wrote:
                [color=blue]
                > As much as I think this is pointless, this might solve the argument,
                > sort of:
                >
                > std::cout << typeid(0).name( );[/color]
                Not really, because an octal integer literal will result in the creation of
                a temporary of type int.
                --
                If our hypothesis is about anything and not about some one or more
                particular things, then our deductions constitute mathematics. Thus
                mathematics may be defined as the subject in which we never know what we
                are talking about, nor whether what we are saying is true.-Bertrand Russell

                Comment

                • Jack Klein

                  #9
                  Re: Is 0 a decimal integer?

                  On Sat, 23 Jul 2005 06:38:41 -0400, "Steven T. Hatton"
                  <chattengau@ger mania.sup> wrote in comp.lang.c++:
                  [color=blue]
                  > I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do agree
                  > with me, then what do you think it is?[/color]

                  I think you are wasting the group's time playing with silly newbie
                  exercises. Suppose some particular compiler gets it wrong, and parses
                  it as a decimal literal. How could you tell the difference?

                  --
                  Jack Klein
                  Home: http://JK-Technology.Com
                  FAQs for
                  comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                  comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                  alt.comp.lang.l earn.c-c++

                  Comment

                  • Steven T. Hatton

                    #10
                    Re: Is 0 a decimal integer?

                    Jack Klein wrote:
                    [color=blue]
                    > On Sat, 23 Jul 2005 06:38:41 -0400, "Steven T. Hatton"
                    > <chattengau@ger mania.sup> wrote in comp.lang.c++:
                    >[color=green]
                    >> I say no, 0 is _not_ a decimal literal. Anybody disagree? If you do
                    >> agree with me, then what do you think it is?[/color]
                    >
                    > I think you are wasting the group's time playing with silly newbie
                    > exercises. Suppose some particular compiler gets it wrong, and parses
                    > it as a decimal literal. How could you tell the difference?[/color]

                    ..

                    --
                    If our hypothesis is about anything and not about some one or more
                    particular things, then our deductions constitute mathematics. Thus
                    mathematics may be defined as the subject in which we never know what we
                    are talking about, nor whether what we are saying is true.-Bertrand Russell

                    Comment

                    • Tescobar

                      #11
                      Re: Is 0 a decimal integer?

                      [color=blue]
                      > I say no, 0 is _not_ a decimal literal. Anybody
                      > disagree? If you do agree
                      > with me, then what do you think it is?[/color]

                      In my opinion, naked zero must be a separate lexical token (from compilers
                      point of view).
                      If not, why is it possible to initialize pointers
                      by zero:

                      some_type* p=0;

                      //or something like this:

                      class a
                      {
                      some_type* pointer;
                      a(): pointer(0) {}
                      };

                      Initializing pointers by integral value is
                      not permitted; you cant write pointer(13).
                      Long time ago there existed something like
                      NULL, which is now depreciated in ANSI c++.
                      Instead of that you use 0 - so it must be
                      something different than any integral number
                      (regardless of octal, decimal, hex, etc).

                      O.C.

                      Comment

                      • Ron Natalie

                        #12
                        Re: Is 0 a decimal integer?

                        Tescobar wrote:[color=blue][color=green]
                        >>I say no, 0 is _not_ a decimal literal. Anybody
                        >>disagree? If you do agree
                        >>with me, then what do you think it is?[/color]
                        >
                        >
                        > In my opinion, naked zero must be a separate lexical token (from compilers
                        > point of view).[/color]

                        It is not. It is an octal integer literal.[color=blue]
                        > If not, why is it possible to initialize pointers
                        > by zero:
                        >
                        > some_type* p=0;[/color]

                        Because the standard says that a null pointer constant is
                        a constant integer expression evaluating to zero. It doesn't
                        have to the 0 token. It can be any constant integer expression
                        with value zero:

                        some_type* p = 3-3;

                        is perfectly valid.

                        Comment

                        Working...