• Re: C and archtecture, C and Java, was Compilers :)

    From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.compilers on Sun Jan 29 19:37:45 2023
    From Newsgroup: comp.compilers

    dave_thompson_2@comcast.net writes:
    [...]
    As well as I know it, C only requires assignment to work for
    pointers cast to (unsigned char *). And once they are cast,
    usually (though I suppose not always), it is done with memcpy(),
    or compared with memcmp().

    Only unsigned char is 100% guaranteed, but on all known systems today
    signed char has no trap rep and also works and so does plain char.
    [...]

    The C standard specifically says that signed char has no padding bits
    (N1570 6.2.6.2p2).

    And plain char has the same representation as either signed char or
    unsigned char, so it also has no padding bits.

    On the other hand, it's best to use unsigned char to access the
    underlying representation. The standard defines the "object
    representation" of a value stored in an object in terms of copying it
    into an array of unsigned char (N1570 6.2.6.1p4). And C still (until
    C23) doesn't mandate 2's-complement for signed types, so that's another
    layer of confusion you can avoid by using unsigned char. (all-bits-1
    could be a trap representation.)

    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    Working, but not speaking, for XCOM Labs
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21b-Linux NewsLink 1.2