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

Keith Thompson <Keith.S.Thompson+u@gmail.com>
Sun, 29 Jan 2023 19:37:45 -0800

          From comp.compilers

Related articles
Compilers :) deavmi@redxen.eu (Tristan B. Velloza Kildaire) (2023-01-02)
Re: Compilers :) DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2023-01-05)
Re: Compilers :) deavmi@redxen.eu (Tristan B. Velloza Kildaire) (2023-01-13)
Re: C and Java, was Compilers :) gah4@u.washington.edu (gah4) (2023-01-13)
Re: C and Java, was Compilers :) gah4@u.washington.edu (gah4) (2023-01-13)
Re: C and Java, was Compilers :) dave_thompson_2@comcast.net (2023-01-28)
Re: C and archtecture, C and Java, was Compilers :) Keith.S.Thompson+u@gmail.com (Keith Thompson) (2023-01-29)
| List of all articles for this month |
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.compilers
Date: Sun, 29 Jan 2023 19:37:45 -0800
Organization: None to speak of
References: 23-01-001 23-01-007 23-01-051 23-01-053 23-01-054 23-01-077
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="51229"; mail-complaints-to="abuse@iecc.com"
Keywords: C, standards
Posted-Date: 30 Jan 2023 12:51:42 EST

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 */


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.