Sixty Four Bit Integer

P

Phil Carmody

Keith Thompson said:
I don't see the difference between using 2's complement and using 2's
complement semantics. Does it matter, as far as the language is
concerned, what kind of hardware is used to implement arithmetic?

No, which is precisely why you shouldn't assert that it does use a
particular type.

Phil
 
W

websnarf

Sometimes!

In C89, there may or may not be any 64-bit integer types.

In C99, there has to be at least one integer type which has at least 64
bits, and there may be types which have more.  The "long long" type has
to have at least 64 bits, and the "int64_t" type has to have exactly 64
bytes or not exist.

In either, any integer type (including char) MAY be 64 or more bits, although
it's unusual for any type shorter than long to be 64 bits.

All of that ignores the fact that many pre-C99 compilers have 64 bit
integers as well. The most comprehensive way to get 64 bit integers
is to download http://www.pobox.com/~qed/pstdin.h and include it then
test for the existence of the definition of INT64_MAX:

#include "pstdint.h" /* http://www.pobox.com/~qed/pstdint.h */

#if defined (INT64_MAX)

/* int64_t is available as a 64 bit type */

#endif

This will work on any C99 compiler as well as a large number of pre-
C99 C compilers.
 
T

Tim Rentsch

Phil Carmody said:
Nit - they don't have to use 2's complement, they have to
provide 2's complement semantics. They can use an abacus
behind the scenes, if need be.

Surely everyone understood that "use 2's complement" was
intended to mean "have a 2's complement representation",
yes? The comment was about what bits are stored in
memory, not about what sort of ALU circuitry might
operate on them.
 
P

Phil Carmody

Tim Rentsch said:
Surely everyone understood that "use 2's complement" was
intended to mean "have a 2's complement representation",
yes?

Yes. Hence my point.
The comment was about what bits are stored in
memory, not about what sort of ALU circuitry might
operate on them.

I hope it wasn't, as that would be wrong. At no point do _bits_
need to be stored in memory in order to provide 2's complement
externally-visible semantics.

Phil
 
T

Tim Rentsch

Phil Carmody said:
Yes. Hence my point.


I hope it wasn't, as that would be wrong. At no point do _bits_
need to be stored in memory in order to provide 2's complement
externally-visible semantics.

I really don't know what point you're trying to make. If we
say an implementation uses 2's complement, it means the
implementation's abstract machine must store a 2's
complement representation in the abstract machine's memory.
If we say an actual machine uses 2's complement, normally it
means that the actual machine stores values in its memory in
a 2's complement representation. I believe I've never heard
the phrase "uses 2's complement", when applied to an actual
machine, to define operations and not also mean what
represenation is used when storing values in memory.
Certainly it would be possible for someone to mean it that
way, but it's never been used that way in my experience.
Are you saying that what's true in the abstract machine need
not be true in the actual machine, because of the "as if"
rule? If so, that's certainly true -- not very interesting,
but still true. Are you saying anything more than that?
 

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,780
Messages
2,569,608
Members
45,251
Latest member
41Ki

Latest Threads

Top