Re: in which form real and integer values are saved in memory



Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> writes:
Keith Thompson <kst-u@xxxxxxx> writes:
Charlton Wilbur <cwilbur@xxxxxxxxxxxxxx> writes:
"BP" == Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:

BP> Ed Prochak <edprochak@xxxxxxxxx> writes:

>> intergers may be big endian or little endian, ones complement or
>> twos complement, BCD or others.

BP> I don't think that BCD is a valid representation for C integer
BP> types.

...unless there's no way for a conforming program to know the
difference.

It would be difficult to arrange that, though not impossible.

Depending on how this statement is meant, the proposition is
either trivially true or wrong.

Clearly a C implementation can use BCD to encode C values
using the simple trick of having one BCD digit per bit.
One octet (two nibbles) would hold two C "bits", or four
octets per char (with CHAR_BIT == 8).

That's not what I had in mind.

However, if "representation" is meant in the sense that
the Standard uses the term (as in "object representation",
for example), integers cannot be represented using
BCD, as that is not consistent with other requirements
for representation of integers.

What I was thinking of was an implementation that uses BCD for integer
representation (so that a stored bit pattern of 0001 0101 represents
the value 15), but that goes through substantial gyrations to make it
*appear* to be using a pure binary representation. If you examined
the underlying representations of objects using, say, a debugger,
you'd see the BCD, but the BCD representation wouldn't leak out to
become visible in the behavior of any program that avoids undefined
behavior. The implementation would satisfy the "least requirements"
of C99 5.1.2.3p5.

This would be a very difficult and silly thing to do, but I'm not
convinced it would violate the standard.

The counterargument is that the representation requirements of 6.2.6.1
must be met by the underlying representation, and that satisfying
5.1.2.3p5 is insufficient.

To put it another way, it should be possible to implement C on top of
a binary virtual machine running on BCD hardware.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: in which form real and integer values are saved in memory
    ... >> intergers may be big endian or little endian, ... >> twos complement, BCD or others. ... BP> I don't think that BCD is a valid representation for C integer ... A strictly conforming program can store a value in an int object, ...
    (comp.lang.c)
  • Re: in which form real and integer values are saved in memory
    ... >> intergers may be big endian or little endian, ... >> twos complement, BCD or others. ... BP> I don't think that BCD is a valid representation for C integer ...
    (comp.lang.c)
  • Re: in which form real and integer values are saved in memory
    ... >> twos complement, BCD or others. ... BP> I don't think that BCD is a valid representation for C integer ... essentially the entire program state at every point). ...
    (comp.lang.c)
  • Re: What about big integers in Ada 2005?
    ... > BCD was originally a six bit representation. ... > the advent of the byte on the IBM System 360, BCD became Extended Binary ... The 6-bit character code was BCDIC -- Binary Coded Decimal Interchange ... > in the picture and a nibble for the sign. ...
    (comp.lang.ada)
  • Re: understanding floats
    ... > exercise) to write floating point math routines that represent numbers ... > an analogous problem for a base 10 representation when dealing with ... and represented BCD numbers in 80 bits. ... I also seem to recall the ...
    (comp.lang.lisp)