Is 0 a decimal integer?

Discussion in 'C++' started by Steven T. Hatton, Jul 23, 2005.

  1. 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
    Steven T. Hatton, Jul 23, 2005
    #1
    1. Advertising

  2. Steven T. Hatton

    benben Guest

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

    Ben
    benben, Jul 23, 2005
    #2
    1. Advertising

  3. benben wrote:

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


    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
    Steven T. Hatton, Jul 23, 2005
    #3
  4. Steven T. Hatton

    Ron Natalie Guest

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


    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.
    Ron Natalie, Jul 23, 2005
    #4
  5. Ron Natalie wrote:

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

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


    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
    Steven T. Hatton, Jul 23, 2005
    #5
  6. Steven T. Hatton

    M.Pfeifer Guest

    "Steven T. Hatton" <> schrieb im Newsbeitrag
    news:...
    > benben wrote:
    >
    > > Doesn't 0 mathematically mean 0 (zero, null, nil) in decimal, binary,
    > > hexadecimal, etc whatever number system you can devise?
    > >
    > > Ben

    >
    > I'm speaking strictly in lexical terms. How would a C++ grammarian

    classify
    > 0? I believe you are correct regarding semantics.
    >


    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
    M.Pfeifer, Jul 23, 2005
    #6
  7. Steven T. Hatton

    Starfox Guest

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

    std::cout << typeid(0).name();
    Starfox, Jul 23, 2005
    #7
  8. Starfox wrote:

    > As much as I think this is pointless, this might solve the argument,
    > sort of:
    >
    > std::cout << typeid(0).name();

    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
    Steven T. Hatton, Jul 23, 2005
    #8
  9. Steven T. Hatton

    Jack Klein Guest

    On Sat, 23 Jul 2005 06:38:41 -0400, "Steven T. Hatton"
    <> wrote in comp.lang.c++:

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


    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.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jul 24, 2005
    #9
  10. Jack Klein wrote:

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

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


    ..

    --
    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
    Steven T. Hatton, Jul 24, 2005
    #10
  11. Steven T. Hatton

    Tescobar Guest


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


    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.
    Tescobar, Jul 24, 2005
    #11
  12. Steven T. Hatton

    Ron Natalie Guest

    Tescobar wrote:
    >>I say no, 0 is _not_ a decimal literal. Anybody
    >>disagree? If you do agree
    >>with me, then what do you think it is?

    >
    >
    > In my opinion, naked zero must be a separate lexical token (from compilers
    > point of view).


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


    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.
    Ron Natalie, Jul 24, 2005
    #12
    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. Ven
    Replies:
    3
    Views:
    1,305
  2. Gilbert Fine
    Replies:
    8
    Views:
    887
    Zentrader
    Aug 1, 2007
  3. Vitaliy
    Replies:
    1
    Views:
    463
    Peter Otten
    May 29, 2008
  4. valpa
    Replies:
    11
    Views:
    1,488
    Steven D'Aprano
    Mar 24, 2009
  5. Replies:
    0
    Views:
    274
Loading...

Share This Page