K&R did not require char to be at least 8 bits, but ANSI did. 

I wonder what C did on a ones' complement machine if a string contained a -0 
character?


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3

________________________________________
From: IBM Mainframe Discussion List [[email protected]] on behalf of 
Bernd Oppolzer [[email protected]]
Sent: Sunday, April 26, 2020 9:49 PM
To: [email protected]
Subject: Re: XL C\C ++ sizeof of datatypes

First of all, char in C is a subtype of int,
which means that you can do normal arithmetic operations to chars
and that chars are allowed in int expressions without special action
needed.

for example:

char c;

c = 'A' + 1;   /* c will be 'B' */
c = c - 'A' + 'a'; /* c will now be 'b' - lower case */

Compare this to Pascal for example, where char and integer are two
different and
incompatible types. To do the same as above in Pascal, you need
conversion functions
(which are part of the Pascal standard):

var c: char;

c := chr (ord ('A') + 1);
c := chr (ord (c) - ord ('A') + ord ('a'));

Back to C:

Now, because chars are small ints in C (much like shorts), they can of
course be signed or unsigned.
If we have 8 bit bytes (which is normal on today's machines, but C would
of course support other
architectures, too), the ranges are -128 .. 127 for signed char (2's
complement) and 0 .. 255 for unsigned char.

If you code

char c;

like in the example above, the char is always signed or unsigned
depending on the default
active during compilation (can probably be modified by compiler option;
if not, there will
be a "factory" setting).

This "factory" setting is unsigned for IBMs z/OS compilers, and signed
for most Windows
and Unix compilers I am aware of.

The reason may be the EBCDIC character set; if signed were used with
EBCDIC, all the
normal characters and digits (X'C1' = 'A', X'F0' = '0') would have
negative char values.
So in my opinion the choice of the unsigned char default is natural for
EBCDIC machines.

The difference between this default has some implications for programs
that want to run
on both platforms (mainframe and PC, for example). I usually cope with
this by explicitly
specifying unsigned char, wherever necessary (only at places, where
computing is done
with character values, for example, when doing hexadecimal output of
storage areas
on both platforms).

BTW: if you want to take a closer look at Pascal, you can find the New
Stanford Pascal Compiler here:

http://secure-web.cisco.com/1ahRAh4N0CSp3gLQZrp-JRlfXHuhuDJQujTXuyt8e3kumDDxT7dDKWO8t8_IBUAYCYZyLxfUBnwWz9AwzGhs7pY99lm_vNvygdilxhlMNOGtSdRImFi-xm9IBnOx249ReXimPEwcmty0CAqDG3LMdyV9rMaKo-Iv6I982Iy_puqJIAAg5OO6aYswgnuVKyNZ3-XRvrm13YGxgkUS0BVP-QPOak9ypU0Mg-1GGxrp8AAw-cmYOzTzNSk1c_pthmqWbtIXAbkgZ7QL5WWm1u6ps0HyKQtC1KIcOviAiEtwR0GSGLBjtDt6kpRT6CFLbkpoP3P6vsM-LLTCKUDcOtsIvCRjbzx1jVP2Creo15L8gE2UoLsF9Dkp23xyAd_wjsHmjgp42wVi8QP-6Rl3jBZkMr519keflDI1nK_klJsTCBzzRjxn3gFq4y2NUyLS6P8rM/http%3A%2F%2Fbernd-oppolzer.de%2Fjob9.htm
https://secure-web.cisco.com/1hHx-M_IeANqdDOt3iYTGkb4FtQQe_aZgDhl66rbSBupoailYOTGHN-d9MY51K9niLKgvpdPWdlhUWsbFRry3TkOzXNALYs_fgVIhkeFhhOEtCUyFdrUT-6IigbGf61pRlye3y62ZlCvF7jlgtoXJvooyUG-uH5Cy9NheskLIXVad3akNA0pg4VqMCIdmPWoDWnbeClK9iq55QfVAi5ixx5NjHqCwUNmh3S8e2eivPmMUhQivNqmLO5JvVehmJAQKf1GjVLhc4k_HGxo7_9_wawW_D0z5nslZSmuBkIKyRxS0pCpvvOFr12jWiuGi6UzKrfaddOW8u62cFsvQUDWbsWO3NaCnz88FwpI4gYJZKR6O1VojfhyTELYB-5sYijvxjvkxBc3kEuz2tVGEwQxiv7ZDBKk11hab85IkWTKha9AWUC_Cc1ylxbj6421yHtcc/https%3A%2F%2Fgithub.com%2FStanfordPascal
https://www.facebook.com/StanfordPascal

which runs on IBM Mainframes (MVS and CMS) and on Windows, Unix (Linux),
OS/2, MacOS etc.;
on the Mainframe, 370 machine code is generated. On the other platforms,
the generated P-Code
is interpreted. The P-Code interpreter PCINT is written in C and (of
course) has to use unsigned chars
to implement the P-instructions in exactly the same way as they are
compiled on the mainframe.

Kind regards

Bernd



Am 26.04.2020 um 23:44 schrieb Charles Mills:
> Without testing, I think that a signed char argument satisfies and unsigned 
> char formal parameter, but that &signed char does not satisfy unsigned char *.
>
> There is some C messiness 
> https://www.facebook.com/StanfordPascal/?eid=ARDEjQaZgVZL2fivkB0AXGk_-mZF97XV3mESzaJ0RR-2NKu0jyroGwFbXt9kqk5UUIUCiHV9d0w2XcfUaround
>  char signage. I think on most platforms char is kind of the same as signed 
> char, but not exactly the same. On Z a char is kind of the same as an 
> unsigned char, but not exactly the same. I am obviously fuzzy on the exact 
> details, and no doubt someone will be happy to set me straight.
>
> Charles

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to