Is 0 a decimal integer?

S

Steven T. Hatton

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

benben

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

Ben
 
S

Steven T. Hatton

benben said:
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.
 
R

Ron Natalie

Steven said:
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.
 
S

Steven T. Hatton

Ron said:
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.
 
M

M.Pfeifer

Steven T. Hatton said:
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
 
S

Starfox

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

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

Steven T. Hatton

Starfox said:
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.
 
J

Jack Klein

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

Steven T. Hatton

Jack said:
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?

..
 
T

Tescobar

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

Ron Natalie

Tescobar said:
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.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top