what is exactly "long long" (newbie)

S

Sting

Hello,
What is exactly "long long" type in "C"?
is it part of a the standard "C" language ?
(i did not find noting in "C"
FAQ and also googling the Internet did not
give any satisfactory results).

regards,
sting
 
A

Andreas Kahari

Hello,
What is exactly "long long" type in "C"?
is it part of a the standard "C" language ?
(i did not find noting in "C"
FAQ and also googling the Internet did not
give any satisfactory results).

It is in the newest standard ("C99"). It is an integer type
which is at least as big as the 'long' type.
 
R

Richard Bos

Andreas Kahari said:
It is in the newest standard ("C99"). It is an integer type
which is at least as big as the 'long' type.

More importantly, it's at least 64 bits, aot long's minimum of 32 bits.

Richard
 
D

Dan Pop

In said:
What is exactly "long long" type in "C"?
is it part of a the standard "C" language ?

long long started its life as an extension in certain Unix compilers and
a standard GNU C feature. It was used as a 64-bit integer type.

The C99 standard adopted it, as an integer type providing at least 64
useful bits.

Since (extremely) few compilers claim C99-conformance, long long cannot
be used in portable C programs. It is, however, handy, if you need a
64-bit integer type and your compiler supports long long.

Dan
 
J

Jack Klein

It is in the newest standard ("C99"). It is an integer type
which is at least as big as the 'long' type.

Er, no, that's not true. There's nothing preventing implementations
on 64 bit platforms using the same 64-bit representation for long and
long long. So let's try...

It is an integer type that is required to have at least 64 bits,
meaning it must have at least twice the range of the minimum required
range for long.

--
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++ ftp://snurse-l.org/pub/acllc-c++/faq
 
A

Andreas Kahari

On Wed, 1 Oct 2003 09:37:20 +0000 (UTC), Andreas Kahari
[long long] is an integer type that is required to have at least 64 bits,
meaning it must have at least twice the range of the minimum required
range for long.

Thank you Jack (and Richard) for sorting out my misconceptions
about this new type.

Since I'm at work and don't have the C standard available (it's
at home) I might as well ask a follow-up question. Does an
integer of type "long long" have to be 64 bits even on a 32-bit
machine?
 
M

Mike Wahler

Andreas Kahari said:
On Wed, 1 Oct 2003 09:37:20 +0000 (UTC), Andreas Kahari
[long long] is an integer type that is required to have at least 64 bits,
meaning it must have at least twice the range of the minimum required
range for long.

Thank you Jack (and Richard) for sorting out my misconceptions
about this new type.

Since I'm at work and don't have the C standard available (it's
at home) I might as well ask a follow-up question. Does an
integer of type "long long" have to be 64 bits even on a 32-bit
machine?

Yes. If it's not possible to implement it on such a machine
(by whatever 'magic' necessary), then it's not possible to
implement a fully conforming implementation. IOW any limitations
of the host machine don't give a language implementation
for it any special exemptions as regards conformance.

-Mike
 
R

Richard Heathfield

Jack said:
Er, no, that's not true.

Er, yes, it is. Andreas's description is neither complete nor sufficient,
but it is certainly correct as far as it goes.
There's nothing preventing implementations
on 64 bit platforms using the same 64-bit representation for long and
long long.

That doesn't actually contradict what Andreas said.
So let's try...

It is an integer type that is required to have at least 64 bits,
meaning it must have at least twice the range of the minimum required
range for long.

That's a much /better/ description, though. :)
 
K

Keith Thompson

Richard Heathfield said:
Jack Klein wrote: [...]
So let's try...

It is an integer type that is required to have at least 64 bits,
meaning it must have at least twice the range of the minimum required
range for long.

That's a much /better/ description, though. :)

Well, it's true that long long has to have at least twice the range of
the minimum required range for long. In fact, it has to have at least
2**32 times the range (assuming that "range" means something like the
number of values it can represent).

Statements about relative sizes rather than relative ranges are
slightly iffy. It's possible (I think) to have

sizeof(long) > sizeof(long long)

if long has more padding bits than long long. I can even imagine a
reason to do it this way. Type long uses the mantissa bits of an
80-bit floating-point type and treats the exponent as padding bits.
Given the hypothetical hardware, this turns out to be the most
efficient way to implement 32-bit integer arithmetic; a mode bit in
the floating-point instructions lets you specify that the exponent has
a fixed value. This 80-bit floating-point type has at least 32 bits
of mantissa, but fewer than 64, so long long is implemented as a pure
64-bit integer type, and operations on it are implemented in some less
efficient way.

I doubt that this would make sense on any real hardware, but I think
it's allowed by the standard.
 
K

Keith Thompson

Keith Thompson said:
Statements about relative sizes rather than relative ranges are
slightly iffy. It's possible (I think) to have

sizeof(long) > sizeof(long long)

if long has more padding bits than long long. I can even imagine a
reason to do it this way. Type long uses the mantissa bits of an
80-bit floating-point type and treats the exponent as padding bits.
Given the hypothetical hardware, this turns out to be the most
efficient way to implement 32-bit integer arithmetic; a mode bit in
the floating-point instructions lets you specify that the exponent has
a fixed value. This 80-bit floating-point type has at least 32 bits
of mantissa, but fewer than 64, so long long is implemented as a pure
64-bit integer type, and operations on it are implemented in some less
efficient way.

I doubt that this would make sense on any real hardware, but I think
it's allowed by the standard.

I may not have made it clear enough that the above description is
entirely hypothetical. In most, perhaps, all, real-world
implementations, type long is represented as an ordinary integer type,
not as some odd variant of a floating-point type.

(This may have been a bit much for a thread with the word "newbie" in
its title.)
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top