Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Totally illogical, there was no chance. -- Spock, "The Galileo Seven", stardate 2822.3


devel / comp.unix.programmer / Why 8 bit exit status codes?

SubjectAuthor
* Why 8 bit exit status codes?Andreas Kempe
+* Re: Why 8 bit exit status codes?Scott Lurndal
|`* Re: Why 8 bit exit status codes?Andreas Kempe
| `* Re: Why 8 bit exit status codes?Scott Lurndal
|  `* Re: Why 8 bit exit status codes?Andreas Kempe
|   +- Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|   `* Re: Why 8 bit exit status codes?Keith Thompson
|    +* Re: Why 8 bit exit status codes?Andreas Kempe
|    |+- Re: Why 8 bit exit status codes?Janis Papanagnou
|    |+- Re: Why 8 bit exit status codes?Scott Lurndal
|    |+- Re: Why 8 bit exit status codes?Keith Thompson
|    |+- Re: Why 8 bit exit status codes?Rainer Weikusat
|    |`- Re: Why 8 bit exit status codes?Andreas Kempe
|    `* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|     `* Re: Why 8 bit exit status codes?Joe Pfeiffer
|      +* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|      |`- Re: Why 8 bit exit status codes?Scott Lurndal
|      +- Re: Why 8 bit exit status codes?Richard Kettlewell
|      `* Re: Why 8 bit exit status codes?Kees Nuyt
|       `* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|        `* Re: Why 8 bit exit status codes?Keith Thompson
|         +- Re: Why 8 bit exit status codes?Scott Lurndal
|         `* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|          `* Re: Why 8 bit exit status codes?Keith Thompson
|           `* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|            `* Re: Why 8 bit exit status codes?Keith Thompson
|             `* Re: Why 8 bit exit status codes?Richard Kettlewell
|              +* Re: Why 8 bit exit status codes?Rainer Weikusat
|              |+* Re: Why 8 bit exit status codes?Kaz Kylheku
|              ||`* Re: Why 8 bit exit status codes?Rainer Weikusat
|              || +* Re: Why 8 bit exit status codes?Kaz Kylheku
|              || |`* Re: Why 8 bit exit status codes?Rainer Weikusat
|              || | `* Re: Why 8 bit exit status codes?Kaz Kylheku
|              || |  `- Re: Why 8 bit exit status codes?Rainer Weikusat
|              || `* Re: Why 8 bit exit status codes?Lew Pitcher
|              ||  `- Re: Why 8 bit exit status codes?Rainer Weikusat
|              |`- Re: Why 8 bit exit status codes?Keith Thompson
|              `* Re: Why 8 bit exit status codes?Keith Thompson
|               +* Re: Why 8 bit exit status codes?Andreas Kempe
|               |`* Re: Why 8 bit exit status codes?Scott Lurndal
|               | `* Re: Why 8 bit exit status codes?Andreas Kempe
|               |  `* Re: Why 8 bit exit status codes?Scott Lurndal
|               |   `* Re: Why 8 bit exit status codes?Andreas Kempe
|               |    `- Re: Why 8 bit exit status codes?Scott Lurndal
|               `* Re: Why 8 bit exit status codes?Richard Kettlewell
|                `* Re: Why 8 bit exit status codes?Rainer Weikusat
|                 `* Re: Why 8 bit exit status codes?Richard Kettlewell
|                  +* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|                  |`- Re: Why 8 bit exit status codes?Richard Kettlewell
|                  `* Re: Why 8 bit exit status codes?Rainer Weikusat
|                   `* Re: Why 8 bit exit status codes?Keith Thompson
|                    `* Re: Why 8 bit exit status codes?Rainer Weikusat
|                     +* Re: Why 8 bit exit status codes?Keith Thompson
|                     |`* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|                     | +* Re: Why 8 bit exit status codes?Scott Lurndal
|                     | |`- Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
|                     | `- Re: Why 8 bit exit status codes?Keith Thompson
|                     `- Re: Why 8 bit exit status codes?Kaz Kylheku
`* Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
 `* Re: Why 8 bit exit status codes?Keith Thompson
  +- Re: Why 8 bit exit status codes?Lawrence D'Oliveiro
  `- Re: Why 8 bit exit status codes?Rainer Weikusat

Pages:123
Why 8 bit exit status codes?

<upj3rq$da8$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11055&group=comp.unix.programmer#11055

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!paganini.bofh.team!pasdenom.info!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.unix.programmer
Subject: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 16:05:14 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <upj3rq$da8$1@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 2 Feb 2024 16:05:14 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="13640"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Fri, 2 Feb 2024 16:05 UTC

Hello everyone,

I'm wondering why, at least on Linux and FreeBSD, a process exit
status was chosen to be only the lower 8 bits in the C interface, i.e.
exit() and wait().

This did bite some colleagues at work at one point who were porting a
modem manager from a real-time OS to Linux because they were returning
negative status codes for errors. We fixed it by changing the status
codes and I never really thought about why this is the state of
things... until now!

Having a look at man 3 exit on my FreeBSD system, it states

>Both functions make the low-order eight bits of the status argument
>available to a parent process which has called a wait(2)-family
>function.

and that it is conforming to the C99 standard

> The exit() and _Exit() functions conform to ISO/IEC 9899:1999
> (“ISO C99”).

C99 7.20.4.3 § 5 states

> Finally, control is returned to the host environment. If the value of
> status is zero or EXIT_SUCCESS, an implementation-defined form of the
> status successful termination is returned. If the value of status is
> EXIT_FAILURE, an implementation-defined form of the status
> unsuccessful termination is returned. Otherwise the status returned
> is implementation-defined.

which I read as the C standard leaving it to the implementation to
decide how to handle the int type argument.

Having a look at man 2 _exit, the system call man page, it says
nothing about the lower 8 bits, but claims conformance with
IEEE Std 1003.1-1990 ("POSIX.1") which says
in Part 1: System Application Program Interface (API) [C Language], 3.2.2.2 § 2

> If the parent process of the calling process is executing a wait() or
> waitpid(), it is notified of the termination of the calling process
> and the low order 8 bits of status are made available to it; see
> 3.2.1.

that only puts a requirement on making the lower 8 bits available.
Looking at a more modern POSIX, IEEE Std 1003.1-2017, that has
waitid() defined, it has the following for _exit()

> The value of status may be 0, EXIT_SUCCESS, EXIT_FAILURE, or any
> other value, though only the least significant 8 bits (that is,
> status & 0377) shall be available from wait() and waitpid(); the
> full value shall be available from waitid() and in the siginfo_t
> passed to a signal handler for SIGCHLD.

so the mystery of why the implementation is the way it is was
dispelled.

The question that remains is what the rationale behind using the lower
8 bits was from the start? Is it historical legacy that no one wanted
to change for backwards compatibility? Is there no need for exit codes
larger than 8 bits?

I don't know if I have ever come into contact with software that deals
with status codes that actually looks at the full value. My daily
driver shell, fish, certainly does not.

--
Best regards,
Andreas Kempe

Re: Why 8 bit exit status codes?

<EP8vN.39265$Wbff.38272@fx37.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11058&group=comp.unix.programmer#11058

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why 8 bit exit status codes?
Newsgroups: comp.unix.programmer
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
Lines: 17
Message-ID: <EP8vN.39265$Wbff.38272@fx37.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 02 Feb 2024 16:33:40 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 02 Feb 2024 16:33:40 GMT
X-Received-Bytes: 1223
 by: Scott Lurndal - Fri, 2 Feb 2024 16:33 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
>Hello everyone,
>
>I'm wondering why, at least on Linux and FreeBSD, a process exit
>status was chosen to be only the lower 8 bits in the C interface, i.e.
>exit() and wait().
>
<snip>

>The question that remains is what the rationale behind using the lower
>8 bits was from the start? Is it historical legacy that no one wanted
>to change for backwards compatibility? Is there no need for exit codes
>larger than 8 bits?

The definition of the wait system call. Recall that the
PDP-11 was a 16-bit computer and wait needed to be able
to include metadata along with the exit status.

Re: Why 8 bit exit status codes?

<upjho8$hek$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11068&group=comp.unix.programmer#11068

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!pasdenom.info!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 20:02:16 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <upjho8$hek$1@nyheter.lysator.liu.se>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
Injection-Date: Fri, 2 Feb 2024 20:02:16 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="17876"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Fri, 2 Feb 2024 20:02 UTC

Den 2024-02-02 skrev Scott Lurndal <scott@slp53.sl.home>:
> Andreas Kempe <kempe@lysator.liu.se> writes:
>>Hello everyone,
>>
>>I'm wondering why, at least on Linux and FreeBSD, a process exit
>>status was chosen to be only the lower 8 bits in the C interface, i.e.
>>exit() and wait().
>>
> <snip>
>
>>The question that remains is what the rationale behind using the lower
>>8 bits was from the start? Is it historical legacy that no one wanted
>>to change for backwards compatibility? Is there no need for exit codes
>>larger than 8 bits?
>
> The definition of the wait system call. Recall that the
> PDP-11 was a 16-bit computer

I'm afraid that's a tall order. I had yet to learn how to read when
they went out of production. :) Please excuse my ignorance.

> and wait needed to be able to include metadata along with the exit
> status.

I'm a bit unclear on the order of things coming into being. Did their
C implementation already use exit() with an int argument of size 16
bits and they also masked? Or was an int 8 bits on PDP-11 with POSIX
opting mask out the lower 8 bits on platforms with wider ints to
maintain backwards compatibility?

Re: Why 8 bit exit status codes?

<w3cvN.322279$c3Ea.250268@fx10.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11069&group=comp.unix.programmer#11069

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.hispagatos.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx10.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why 8 bit exit status codes?
Newsgroups: comp.unix.programmer
References: <upj3rq$da8$1@nyheter.lysator.liu.se> <EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
Lines: 49
Message-ID: <w3cvN.322279$c3Ea.250268@fx10.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 02 Feb 2024 20:15:24 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 02 Feb 2024 20:15:24 GMT
X-Received-Bytes: 2612
 by: Scott Lurndal - Fri, 2 Feb 2024 20:15 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
>Den 2024-02-02 skrev Scott Lurndal <scott@slp53.sl.home>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:
>>>Hello everyone,
>>>
>>>I'm wondering why, at least on Linux and FreeBSD, a process exit
>>>status was chosen to be only the lower 8 bits in the C interface, i.e.
>>>exit() and wait().
>>>
>> <snip>
>>
>>>The question that remains is what the rationale behind using the lower
>>>8 bits was from the start? Is it historical legacy that no one wanted
>>>to change for backwards compatibility? Is there no need for exit codes
>>>larger than 8 bits?
>>
>> The definition of the wait system call. Recall that the
>> PDP-11 was a 16-bit computer
>
>I'm afraid that's a tall order. I had yet to learn how to read when
>they went out of production. :) Please excuse my ignorance.
>
>> and wait needed to be able to include metadata along with the exit
>> status.
>
>I'm a bit unclear on the order of things coming into being. Did their
>C implementation already use exit() with an int argument of size 16
>bits and they also masked? Or was an int 8 bits on PDP-11 with POSIX
>opting mask out the lower 8 bits on platforms with wider ints to
>maintain backwards compatibility?

The status argument to the wait system call returned
a two part value; 8 bits of exit status and 8 bits
that describe the termination conditions (e.g. the
signal number that stopped or terminated the
process).

Here's the modern 32-bit layout (in little endian form):

unsigned int __w_termsig:7; /* Terminating signal. */
unsigned int __w_coredump:1; /* Set if dumped core. */
unsigned int __w_retcode:8; /* Return code if exited normally. */
unsigned int:16;

It's just the PDP-11 unix 16-bit version with 16 unused padding bits.

SVR4 added the waitid(2) system call which via the siginfo argument has
access to the full 32-bit program exit status.

Re: Why 8 bit exit status codes?

<upjlu5$2oup9$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11075&group=comp.unix.programmer#11075

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 21:13:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <upjlu5$2oup9$2@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 2 Feb 2024 21:13:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2132941f276938b37dd44911619c6d41";
logging-data="2915113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NedxHIFWJVGv8o+CRNehA"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:XLeTCiSA6Zhisr+UKT+4PBHZJc0=
 by: Lawrence D'Oliv - Fri, 2 Feb 2024 21:13 UTC

On Fri, 2 Feb 2024 16:05:14 -0000 (UTC), Andreas Kempe wrote:

> I'm wondering why, at least on Linux and FreeBSD, a process exit status
> was chosen to be only the lower 8 bits in the C interface, i.e.
> exit() and wait().

I’ve never used that many different values. E.g. 0 for some test condition
passed, 1 for failed, 2 for unexpected error.

> This did bite some colleagues at work at one point who were porting a
> modem manager from a real-time OS to Linux because they were returning
> negative status codes for errors.

True enough:

ldo@theon:~> python3 -c "import sys; sys.exit(1)"; echo $?
1
ldo@theon:~> python3 -c "import sys; sys.exit(-1)"; echo $?
255

But you could always sign-extend it.

Re: Why 8 bit exit status codes?

<upjmam$hek$2@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11077&group=comp.unix.programmer#11077

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.samoylyk.net!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 21:20:22 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <upjmam$hek$2@nyheter.lysator.liu.se>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
Injection-Date: Fri, 2 Feb 2024 21:20:22 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="17876"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Fri, 2 Feb 2024 21:20 UTC

Den 2024-02-02 skrev Scott Lurndal <scott@slp53.sl.home>:
> Andreas Kempe <kempe@lysator.liu.se> writes:
>>I'm a bit unclear on the order of things coming into being. Did their
>>C implementation already use exit() with an int argument of size 16
>>bits and they also masked? Or was an int 8 bits on PDP-11 with POSIX
>>opting mask out the lower 8 bits on platforms with wider ints to
>>maintain backwards compatibility?
>
> The status argument to the wait system call returned
> a two part value; 8 bits of exit status and 8 bits
> that describe the termination conditions (e.g. the
> signal number that stopped or terminated the
> process).
>
>
> Here's the modern 32-bit layout (in little endian form):
>
> unsigned int __w_termsig:7; /* Terminating signal. */
> unsigned int __w_coredump:1; /* Set if dumped core. */
> unsigned int __w_retcode:8; /* Return code if exited normally. */
> unsigned int:16;
>
> It's just the PDP-11 unix 16-bit version with 16 unused padding bits.
>

Thank you for the clarification, but I don't think I have any problem
grasping how the implementation works. My thought are why they did
what they did.

Why not use a char in exit() instead of int, with wait() returning the
full 16 bits? If the program itself fills in the upper 8 bits, it
makes sense, but otherwise I don't understand from an API perspective
why one would use a data type with the caveat that only half is used.

If we already have exit() and wait() using ints and want to stuff our
extra information in there without changing the API, it also makes
sense.

> SVR4 added the waitid(2) system call which via the siginfo argument has
> access to the full 32-bit program exit status.

Re: Why 8 bit exit status codes?

<87le82o907.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11079&group=comp.unix.programmer#11079

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 02 Feb 2024 13:23:52 -0800
Organization: None to speak of
Lines: 32
Message-ID: <87le82o907.fsf@nosuchdomain.example.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<upjlu5$2oup9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="a25c07b6296b5291e04aff5e5cd7fea7";
logging-data="2917765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tttfzQNfkR0rwg02xZl6w"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:dYzGjB4OAOTxgfNOPljWII0b1vY=
sha1:kJIpIrHm9S8efgHP1qFiYW+7ycs=
 by: Keith Thompson - Fri, 2 Feb 2024 21:23 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Fri, 2 Feb 2024 16:05:14 -0000 (UTC), Andreas Kempe wrote:
>
>> I'm wondering why, at least on Linux and FreeBSD, a process exit status
>> was chosen to be only the lower 8 bits in the C interface, i.e.
>> exit() and wait().
>
> I’ve never used that many different values. E.g. 0 for some test condition
> passed, 1 for failed, 2 for unexpected error.

The curl command defines nearly 100 error codes ("man curl" for
details). That's the most I've seen. 8 bits is almost certainly
plenty if the goal is to enumerate specific error conditions.
It's not enough if you want to pass more information through the
error code, which is why most programs don't try to do that.

Since int is typically 32 bits (but only guaranteed by C to be at
least 16), the exit() function could theoretically be used to pass
32 bits of information, but that's not really much more useful than 8
bits. If a program needs to return more than 8 bits of information,
it will typically print a string to stdout or something similar.

(On Plan 9, a program's exit status is (was?) a string, empty for
success, a description of the error condition on error. It's a cool
idea, but I can imagine it introducing some interesting problems.)

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why 8 bit exit status codes?

<upjndd$2oup9$9@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11080&group=comp.unix.programmer#11080

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 21:38:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <upjndd$2oup9$9@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<upjlu5$2oup9$2@dont-email.me> <87le82o907.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 2 Feb 2024 21:38:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2132941f276938b37dd44911619c6d41";
logging-data="2915113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18F3MLJVzvLC8eYHzWt8cOQ"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:R5GqzoaYMSWcXh91A1P75XUcKzk=
 by: Lawrence D'Oliv - Fri, 2 Feb 2024 21:38 UTC

On Fri, 02 Feb 2024 13:23:52 -0800, Keith Thompson wrote:

> The curl command defines nearly 100 error codes ("man curl" for
> details). That's the most I've seen.

Another reason for staying away from curl, I would say. It needlessly
replicates the functionality of a whole lot of different protocol clients,
when all you need is HTTP/HTTPS (maybe FTP/FTPS as well). That’s why I
stick to wget.

> (On Plan 9, a program's exit status is (was?) a string, empty for
> success, a description of the error condition on error. It's a cool
> idea, but I can imagine it introducing some interesting problems.)

What, not a JSON object?

Re: Why 8 bit exit status codes?

<upjngf$2oup9$10@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11081&group=comp.unix.programmer#11081

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!nntp.comgw.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 2 Feb 2024 21:40:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <upjngf$2oup9$10@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 2 Feb 2024 21:40:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2132941f276938b37dd44911619c6d41";
logging-data="2915113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BF2MxilYqT4CSpLpWmI07"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:zRmUybUy/cav9YnUvLmAOIpsZcc=
 by: Lawrence D'Oliv - Fri, 2 Feb 2024 21:40 UTC

On Fri, 2 Feb 2024 21:20:22 -0000 (UTC), Andreas Kempe wrote:

> Why not use a char in exit() instead of int, with wait() returning the
> full 16 bits? If the program itself fills in the upper 8 bits, it makes
> sense, but otherwise I don't understand from an API perspective why one
> would use a data type with the caveat that only half is used.

The other half contains information like whether the low half is actually
an explicit exit code, or something else like a signal that killed the
process. Or an indication that the process has not actually terminated,
but is just stopped.

Re: Why 8 bit exit status codes?

<87cytenve7.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11089&group=comp.unix.programmer#11089

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Fri, 02 Feb 2024 18:17:52 -0800
Organization: None to speak of
Lines: 56
Message-ID: <87cytenve7.fsf@nosuchdomain.example.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="026cbd12272797f54d5c091ea0e8c8d6";
logging-data="2999751"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186YrXLtINKRCV3pFBHDdur"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ALKQ42vV7nbvvXS3uHGsfeZANfM=
sha1:1+mu/aPk3tZPciXZ9/r01P7uKrw=
 by: Keith Thompson - Sat, 3 Feb 2024 02:17 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
> Den 2024-02-02 skrev Scott Lurndal <scott@slp53.sl.home>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:
>>>I'm a bit unclear on the order of things coming into being. Did their
>>>C implementation already use exit() with an int argument of size 16
>>>bits and they also masked? Or was an int 8 bits on PDP-11 with POSIX
>>>opting mask out the lower 8 bits on platforms with wider ints to
>>>maintain backwards compatibility?
>>
>> The status argument to the wait system call returned
>> a two part value; 8 bits of exit status and 8 bits
>> that describe the termination conditions (e.g. the
>> signal number that stopped or terminated the
>> process).
>>
>>
>> Here's the modern 32-bit layout (in little endian form):
>>
>> unsigned int __w_termsig:7; /* Terminating signal. */
>> unsigned int __w_coredump:1; /* Set if dumped core. */
>> unsigned int __w_retcode:8; /* Return code if exited normally. */
>> unsigned int:16;
>>
>> It's just the PDP-11 unix 16-bit version with 16 unused padding bits.
>>
>
> Thank you for the clarification, but I don't think I have any problem
> grasping how the implementation works. My thought are why they did
> what they did.
>
> Why not use a char in exit() instead of int, with wait() returning the
> full 16 bits? If the program itself fills in the upper 8 bits, it
> makes sense, but otherwise I don't understand from an API perspective
> why one would use a data type with the caveat that only half is used.

C tends to use int values even for character data (when not an element
of a string). See for example the return types of getchar(), fgetc(),
et al, and even the type of character constants ('x' is of type int, not
char).

In early C, int was in many ways a kind of default type. Functions with
no visible declaration were assumed to return int. The signedness of
plain char is implementation-defined. Supporting exit values from 0 to
255 is fairly reasonable. Using an int to store that value is also
fairly reasonable -- especially since main() returns int, and exit(n) is
very nearly equivalent to return n in main().

Ignoring all but the low-order 8 bits is not specified by C. Non-POSIX
systems can use all 32 (or 16, or ...) bits of the return value.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why 8 bit exit status codes?

<uplekp$133i$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11104&group=comp.unix.programmer#11104

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sat, 3 Feb 2024 13:21:29 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <uplekp$133i$1@nyheter.lysator.liu.se>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
Injection-Date: Sat, 3 Feb 2024 13:21:29 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="35954"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Sat, 3 Feb 2024 13:21 UTC

Den 2024-02-03 skrev Keith Thompson <Keith.S.Thompson+u@gmail.com>:
> Andreas Kempe <kempe@lysator.liu.se> writes:
>>
>> Why not use a char in exit() instead of int, with wait() returning the
>> full 16 bits? If the program itself fills in the upper 8 bits, it
>> makes sense, but otherwise I don't understand from an API perspective
>> why one would use a data type with the caveat that only half is used.
>
> C tends to use int values even for character data (when not an element
> of a string). See for example the return types of getchar(), fgetc(),
> et al, and even the type of character constants ('x' is of type int, not
> char).
>

I thought the reason for the int return type was to have an error code
outside of the range of the valid data, with EOF being defined as
being a negative integer. A reason that isn't applicable for the
argument passing to exit by a program.

> In early C, int was in many ways a kind of default type. Functions with
> no visible declaration were assumed to return int. The signedness of
> plain char is implementation-defined.

I realised that char was a bad example just as I posted. I should have
chosen unsigned char instead.

> Supporting exit values from 0 to 255 is fairly reasonable. Using an
> int to store that value is also fairly reasonable -- especially
> since main() returns int, and exit(n) is very nearly equivalent to
> return n in main(). Ignoring all but the low-order 8 bits is not
> specified by C. Non-POSIX systems can use all 32 (or 16, or ...)
> bits of the return value.
>

Yes, in my original post, I detailed that the restriction does not
come from the C standard, but from POSIX. I'm not sure which came
first.

If C was first with having an exit() function and an int return for
main, I can imagine that it went something like this

- C chooses int for main
- C uses int in exit() to match main
- OS folks want to store extra data in the exit status, but they
want to match the C API
- let's just stuff it in the upper bits and keep the API the same with
an imposed restriction on the value in POSIX

or POSIX exit() was constructed with the int from main in mind, or it
could just be, as you point out, that int is a nice default integer
type and there wasn't much thought put into it beyond that.

I can speculate a bunch different reasons, but I'm curious if anyone
knows what the actual reasoning was.

Re: Why 8 bit exit status codes?

<uplmm0$36943$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11113&group=comp.unix.programmer#11113

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sat, 3 Feb 2024 16:38:39 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <uplmm0$36943$1@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<uplekp$133i$1@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 3 Feb 2024 15:38:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb5e74a4e7ce8bc070d1f38670b72a56";
logging-data="3351683"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tQQHSt8VriVDtyK3yi50b"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:7saeTVc3+RXP16ApnL/AeqgAjC0=
In-Reply-To: <uplekp$133i$1@nyheter.lysator.liu.se>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Sat, 3 Feb 2024 15:38 UTC

On 03.02.2024 14:21, Andreas Kempe wrote:
> Den 2024-02-03 skrev Keith Thompson <Keith.S.Thompson+u@gmail.com>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:
>>>
>>> Why not use a char in exit() instead of int, with wait() returning the
>>> full 16 bits? If the program itself fills in the upper 8 bits, it
>>> makes sense, but otherwise I don't understand from an API perspective
>>> why one would use a data type with the caveat that only half is used.
>>
>> C tends to use int values even for character data (when not an element
>> of a string). See for example the return types of getchar(), fgetc(),
>> et al, and even the type of character constants ('x' is of type int, not
>> char).
>>
>
> I thought the reason for the int return type was to have an error code
> outside of the range of the valid data, with EOF being defined as
> being a negative integer. A reason that isn't applicable for the
> argument passing to exit by a program.
>
>> In early C, int was in many ways a kind of default type. Functions with
>> no visible declaration were assumed to return int. The signedness of
>> plain char is implementation-defined.
>
> I realised that char was a bad example just as I posted. I should have
> chosen unsigned char instead.
>
>> Supporting exit values from 0 to 255 is fairly reasonable. Using an
>> int to store that value is also fairly reasonable -- especially
>> since main() returns int, and exit(n) is very nearly equivalent to
>> return n in main(). Ignoring all but the low-order 8 bits is not
>> specified by C. Non-POSIX systems can use all 32 (or 16, or ...)
>> bits of the return value.
>>
>
> Yes, in my original post, I detailed that the restriction does not
> come from the C standard, but from POSIX. I'm not sure which came
> first.
>
> If C was first with having an exit() function and an int return for
> main, I can imagine that it went something like this
>
> - C chooses int for main
> - C uses int in exit() to match main
> - OS folks want to store extra data in the exit status, but they
> want to match the C API
> - let's just stuff it in the upper bits and keep the API the same with
> an imposed restriction on the value in POSIX
>
> or POSIX exit() was constructed with the int from main in mind, or it
> could just be, as you point out, that int is a nice default integer
> type and there wasn't much thought put into it beyond that.
>
> I can speculate a bunch different reasons, but I'm curious if anyone
> knows what the actual reasoning was.

AFAICT; "historical reasons". You have some bits to carry some exit
status, some bits to carry other termination information (signals),
optionally some more bits to carry other supplementary information.
If you want that information all carried across a single primitive
data type you have to draw a line somewhere. Given that these days
one can not assume that more than 16 bit in the default 'int' type
guaranteed it seems quite obvious to split at 8 bit. (For practical
reasons differentiating 255 error codes seems more than enough, if
we consider what evaluating and individually acting on all of them
at the calling/environment level would mean.)

Janis

Re: Why 8 bit exit status codes?

<FjyvN.104509$JLvf.90481@fx44.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11128&group=comp.unix.programmer#11128

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx44.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why 8 bit exit status codes?
Newsgroups: comp.unix.programmer
References: <upj3rq$da8$1@nyheter.lysator.liu.se> <EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se> <w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se> <87cytenve7.fsf@nosuchdomain.example.com> <uplekp$133i$1@nyheter.lysator.liu.se>
Lines: 23
Message-ID: <FjyvN.104509$JLvf.90481@fx44.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 03 Feb 2024 21:34:29 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 03 Feb 2024 21:34:29 GMT
X-Received-Bytes: 1833
 by: Scott Lurndal - Sat, 3 Feb 2024 21:34 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
>Den 2024-02-03 skrev Keith Thompson <Keith.S.Thompson+u@gmail.com>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:

>Yes, in my original post, I detailed that the restriction does not
>come from the C standard, but from POSIX. I'm not sure which came
>first.

The restriction predates both. It was how unix v6 worked; every
version of unix thereafter continued that so that existing applications
would not need to be rewritten.

It was documented in the SVID (System V Interface Definition) which
was part of the source materials used by X/Open when developing
the X Portability Guides (xpg) (which became the SuS).

Ken and Dennis chose to implement the wait system call (which
the shell uses to collect the exit status) with an 8-bit value
so they could use the other 8 bits of the 16-bit int for metadata.

This could never be changed without breaking applications, so
we still have it today in unix, linux and other POSIX-compliant
operating evironments.

Re: Why 8 bit exit status codes?

<upmbnj$39vft$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11130&group=comp.unix.programmer#11130

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sat, 3 Feb 2024 21:37:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <upmbnj$39vft$2@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 3 Feb 2024 21:37:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="30ce9394578c0c104a3323bda7e13968";
logging-data="3472893"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ljvs33JIcqPlb0O/pC5bm"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:U/tRXV7BNiLPM5kg2oyfQMNenQ8=
 by: Lawrence D'Oliv - Sat, 3 Feb 2024 21:37 UTC

On Fri, 02 Feb 2024 18:17:52 -0800, Keith Thompson wrote:

> The signedness of plain char is implementation-defined.

Why? Because the PDP-11 on which C and Unix were originally developed did
sign extension when loading a byte quantity into a (word-length) register.

Signed characters make no sense.

Re: Why 8 bit exit status codes?

<87fry9m8jf.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11134&group=comp.unix.programmer#11134

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sat, 03 Feb 2024 15:29:08 -0800
Organization: None to speak of
Lines: 41
Message-ID: <87fry9m8jf.fsf@nosuchdomain.example.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<uplekp$133i$1@nyheter.lysator.liu.se>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="1e44218e6d1b3ee096a2122e7ebd5fda";
logging-data="3507170"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T8tWIxS4ySMiliMY1uy2o"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:e1fChAfDjZqm49uzma2gdVBdCY0=
sha1:mQwme/8/IptuMHRLk3+yJI54X30=
 by: Keith Thompson - Sat, 3 Feb 2024 23:29 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
> Den 2024-02-03 skrev Keith Thompson <Keith.S.Thompson+u@gmail.com>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:
>>>
>>> Why not use a char in exit() instead of int, with wait() returning the
>>> full 16 bits? If the program itself fills in the upper 8 bits, it
>>> makes sense, but otherwise I don't understand from an API perspective
>>> why one would use a data type with the caveat that only half is used.
>>
>> C tends to use int values even for character data (when not an element
>> of a string). See for example the return types of getchar(), fgetc(),
>> et al, and even the type of character constants ('x' is of type int, not
>> char).
>
> I thought the reason for the int return type was to have an error code
> outside of the range of the valid data, with EOF being defined as
> being a negative integer. A reason that isn't applicable for the
> argument passing to exit by a program.

I don't think there's one definitive reason for either decision.

>> In early C, int was in many ways a kind of default type. Functions with
>> no visible declaration were assumed to return int. The signedness of
>> plain char is implementation-defined.
>
> I realised that char was a bad example just as I posted. I should have
> chosen unsigned char instead.

The exit() function predates unsigned char (see K&R1). It probably even
predates char. (C's predecessor B was untyped, with characters being
stored in words which were effectively of type int. There was an exit()
function, but it apparently took no arguments.)

Changing exit()'s parameter type to reflect the range of valid values
undoubtedly wasn't considered worth doing -- especially since a wider
range of values might be valid on some systems.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Why 8 bit exit status codes?

<1bwmrkaoow.fsf@pfeifferfamily.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11139&group=comp.unix.programmer#11139

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pfeif...@cs.nmsu.edu (Joe Pfeiffer)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sat, 03 Feb 2024 20:33:19 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <1bwmrkaoow.fsf@pfeifferfamily.net>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<upmbnj$39vft$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="5d412c63830c73ee0edbe27eb43a4f5f";
logging-data="3693815"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18oaGXnRyMB0piYS7SV5jA2xAttO3rN38c="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:vvoNfxuz5r6uodW608Wqdy/dvMc=
sha1:Y8apdiUWXX9ZeS5ll9YAbGPUBuM=
 by: Joe Pfeiffer - Sun, 4 Feb 2024 03:33 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> On Fri, 02 Feb 2024 18:17:52 -0800, Keith Thompson wrote:
>
>> The signedness of plain char is implementation-defined.
>
> Why? Because the PDP-11 on which C and Unix were originally developed did
> sign extension when loading a byte quantity into a (word-length) register.
>
> Signed characters make no sense.

Except in architectures where they do. If you're doing something where
it matters (or even if you want your code to be more readable) used
signed char or unsigned char as appropriate.

Re: Why 8 bit exit status codes?

<upnbil$3i0cg$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11145&group=comp.unix.programmer#11145

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sun, 4 Feb 2024 06:41:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <upnbil$3i0cg$4@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com> <upmbnj$39vft$2@dont-email.me>
<1bwmrkaoow.fsf@pfeifferfamily.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 4 Feb 2024 06:41:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="29ee133c86c3ce52220b03c91f891a2d";
logging-data="3735952"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VYEbLzS4713H88lBltyQj"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:6sjIV1iTYSzDN1EDCDINWHdI+eU=
 by: Lawrence D'Oliv - Sun, 4 Feb 2024 06:41 UTC

On Sat, 03 Feb 2024 20:33:19 -0700, Joe Pfeiffer wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Fri, 02 Feb 2024 18:17:52 -0800, Keith Thompson wrote:
>>
>>> The signedness of plain char is implementation-defined.
>>
>> Why? Because the PDP-11 on which C and Unix were originally developed
>> did sign extension when loading a byte quantity into a (word-length)
>> register.
>>
>> Signed characters make no sense.
>
> Except in architectures where they do.

There are no character encodings which assign meanings to negative codes.

Re: Why 8 bit exit status codes?

<wwvv874k41i.fsf@LkoBDZeT.terraraq.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11148&group=comp.unix.programmer#11148

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: inva...@invalid.invalid (Richard Kettlewell)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Sun, 04 Feb 2024 08:49:13 +0000
Organization: terraraq NNTP server
Message-ID: <wwvv874k41i.fsf@LkoBDZeT.terraraq.uk>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<upmbnj$39vft$2@dont-email.me> <1bwmrkaoow.fsf@pfeifferfamily.net>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
logging-data="43178"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:BrhYBZkyB8LLT1fljlrqDmvREXM=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
+r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
 by: Richard Kettlewell - Sun, 4 Feb 2024 08:49 UTC

Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>> On Fri, 02 Feb 2024 18:17:52 -0800, Keith Thompson wrote:
>>> The signedness of plain char is implementation-defined.
>>
>> Why? Because the PDP-11 on which C and Unix were originally developed did
>> sign extension when loading a byte quantity into a (word-length) register.
>>
>> Signed characters make no sense.
>
> Except in architectures where they do.

Such as?

> If you're doing something where it matters (or even if you want your
> code to be more readable) used signed char or unsigned char as
> appropriate.

Signed 8-bit integers are perfectly sensible, signed characters not so
much.

--
https://www.greenend.org.uk/rjk/

Re: Why 8 bit exit status codes?

<zTOvN.199163$yEgf.96219@fx09.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11157&group=comp.unix.programmer#11157

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Why 8 bit exit status codes?
Newsgroups: comp.unix.programmer
References: <upj3rq$da8$1@nyheter.lysator.liu.se> <EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se> <w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se> <87cytenve7.fsf@nosuchdomain.example.com> <upmbnj$39vft$2@dont-email.me> <1bwmrkaoow.fsf@pfeifferfamily.net> <upnbil$3i0cg$4@dont-email.me>
Lines: 25
Message-ID: <zTOvN.199163$yEgf.96219@fx09.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sun, 04 Feb 2024 16:25:03 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sun, 04 Feb 2024 16:25:03 GMT
X-Received-Bytes: 1788
 by: Scott Lurndal - Sun, 4 Feb 2024 16:25 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>On Sat, 03 Feb 2024 20:33:19 -0700, Joe Pfeiffer wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> On Fri, 02 Feb 2024 18:17:52 -0800, Keith Thompson wrote:
>>>
>>>> The signedness of plain char is implementation-defined.
>>>
>>> Why? Because the PDP-11 on which C and Unix were originally developed
>>> did sign extension when loading a byte quantity into a (word-length)
>>> register.
>>>
>>> Signed characters make no sense.
>>
>> Except in architectures where they do.
>
>There are no character encodings which assign meanings to negative codes.

But then 'signed char' doesn't necessarily need to be used
for character encoding (consider int8_t, for example, which
defines a signed arithmetic type from -128..+127.

On the 16-bit PDP-11, signed 8-bit values would not have been uncommon,
if only because of the limited address space.

Re: Why 8 bit exit status codes?

<87bk8unb6q.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11196&group=comp.unix.programmer#11196

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 05 Feb 2024 16:11:09 +0000
Lines: 37
Message-ID: <87bk8unb6q.fsf@doppelsaurus.mobileactivedefense.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<uplekp$133i$1@nyheter.lysator.liu.se>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net dGr74zlgxyFKPO0PWkaKpwNFRzdMO3Rj/sTf/hgUY3dgwuyEA=
Cancel-Lock: sha1:1PQp39PqrQo84cmA2oyrx+DL6Ak= sha1:+szvhqVmCpw9LEZw0HI6deFLqvE= sha256:TxEgH/ZWXnx0xMYy9VtN7xC7+uv15+Od/UgRFlwBnDg=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Mon, 5 Feb 2024 16:11 UTC

Andreas Kempe <kempe@lysator.liu.se> writes:
> Den 2024-02-03 skrev Keith Thompson <Keith.S.Thompson+u@gmail.com>:
>> Andreas Kempe <kempe@lysator.liu.se> writes:

[...]

> If C was first with having an exit() function and an int return for
> main, I can imagine that it went something like this
>
> - C chooses int for main
> - C uses int in exit() to match main
> - OS folks want to store extra data in the exit status, but they
> want to match the C API
> - let's just stuff it in the upper bits and keep the API the same with
> an imposed restriction on the value in POSIX
>
> or POSIX exit() was constructed with the int from main in mind, or it
> could just be, as you point out, that int is a nice default integer
> type and there wasn't much thought put into it beyond that.
>
> I can speculate a bunch different reasons, but I'm curious if anyone
> knows what the actual reasoning was.

This should be pretty obvious: A C int is really a machine data type in
disguise, namely, whatever fits into a common general purpose register
of a certain machine. C was created for porting UNIX to
the PDP-11 (or rather, rewriting UNIX for the PDP-11 with the goal of
not having to rewrite it again for next type of machine which would need
to be supported by it). Putting a value into a certain register is a
common convention for returning values from functions (or rather, Dennis
Ritchie probably thought it would be a sensible convention at that
time). Hence, having main return an int was the 'natural' idea and
allocating the lower half of this int to applications whising to return
status codes and the upper half to the system for returning
system-specific metadata was also the 'natural' idea.

Surely, eight whole bits must be enough for everyone! :-)

Re: Why 8 bit exit status codes?

<877cjinb3v.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11197&group=comp.unix.programmer#11197

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 05 Feb 2024 16:12:52 +0000
Lines: 11
Message-ID: <877cjinb3v.fsf@doppelsaurus.mobileactivedefense.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<upjlu5$2oup9$2@dont-email.me>
<87le82o907.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net twLdDOg4y/QAC+gtdDVxmA6nryo2TG7VKEhpNoEvUnNFKtgsE=
Cancel-Lock: sha1:sYFYR50eLkvT7ZDc8AT3cWKmCIk= sha1:yWDSFWDlQhRp4z00vrTkZQLjcxI= sha256:2Pt7NXGvm23aJ7wSgQxMhhb0zgXXmpcP06kL/nIkPX8=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Mon, 5 Feb 2024 16:12 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

[...]

> (On Plan 9, a program's exit status is (was?) a string, empty for
> success, a description of the error condition on error. It's a cool
> idea, but I can imagine it introducing some interesting problems.)

That's interesting to know as I have been using the same convention for
validation functions in Perl for some years: These return nothing when
everything was ok or a textual error message otherwise.

Re: Why 8 bit exit status codes?

<qv52si5cvkajlf7fdcidur6elhism0u2su@dim53.demon.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11202&group=comp.unix.programmer#11202

  copy link   Newsgroups: comp.unix.programmer
From: k.n...@nospam.demon.nl (Kees Nuyt)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 05 Feb 2024 18:22:59 +0100
Reply-To: k.nuyt@nospam.demon.nl
Message-ID: <qv52si5cvkajlf7fdcidur6elhism0u2su@dim53.demon.nl>
References: <upj3rq$da8$1@nyheter.lysator.liu.se> <EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se> <w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se> <87cytenve7.fsf@nosuchdomain.example.com> <upmbnj$39vft$2@dont-email.me> <1bwmrkaoow.fsf@pfeifferfamily.net>
User-Agent: ForteAgent/7.10.32.1214
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!2001:67c:174:101:1:67:202:5.MISMATCH!feed.abavia.com!abe005.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 15
Injection-Date: Mon, 05 Feb 2024 18:22:59 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1480
 by: Kees Nuyt - Mon, 5 Feb 2024 17:22 UTC

On Sat, 03 Feb 2024 20:33:19 -0700, Joe Pfeiffer
<pfeiffer@cs.nmsu.edu> wrote:

> Signed characters make no sense.

Nor did 6 bit characters, but in the 1980s we had them:
3 characters in a 24 bit word.
Welcome to what was then called mini or midrange computers.

(Yes, looking at you, Harris, with its Vulcan Operating System)

--
Regards,
Kees Nuyt

Re: Why 8 bit exit status codes?

<uprbc0$2rb8$1@nyheter.lysator.liu.se>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11209&group=comp.unix.programmer#11209

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kem...@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 5 Feb 2024 19:02:24 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <uprbc0$2rb8$1@nyheter.lysator.liu.se>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<uplekp$133i$1@nyheter.lysator.liu.se>
Injection-Date: Mon, 5 Feb 2024 19:02:24 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="93544"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Mon, 5 Feb 2024 19:02 UTC

Thank you everyone for the different informative replies and
historical insight! I think I have gotten what I can out of this
thread.

Re: Why 8 bit exit status codes?

<upro72$g01t$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11221&group=comp.unix.programmer#11221

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 5 Feb 2024 22:41:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <upro72$g01t$2@dont-email.me>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad> <upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad> <upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com> <upmbnj$39vft$2@dont-email.me>
<1bwmrkaoow.fsf@pfeifferfamily.net>
<qv52si5cvkajlf7fdcidur6elhism0u2su@dim53.demon.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 5 Feb 2024 22:41:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f9f0728b32a146e99d37fd009fb7e64d";
logging-data="524349"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+evgXxHowMIrM5wiPRM+Aq"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:HStH6y/UKmyrTqM9oR/FCUbJ4DE=
 by: Lawrence D'Oliv - Mon, 5 Feb 2024 22:41 UTC

On Mon, 05 Feb 2024 18:22:59 +0100, Kees Nuyt wrote:

> On Sat, 3 Feb 2024 21:37:55 -0000 (UTC), Lawrence D'Oliveiro wrote:
>
> Signed characters make no sense.
>
> Nor did 6 bit characters, but in the 1980s we had them:
> 3 characters in a 24 bit word.

I see your sixbit and raise you Radix-50, which packed 3 characters into a
16-bit word.

None of these used signed character codes, by the way. So my point still
stands.

Re: Why 8 bit exit status codes?

<87cytajwqe.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11225&group=comp.unix.programmer#11225

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Why 8 bit exit status codes?
Date: Mon, 05 Feb 2024 15:51:37 -0800
Organization: None to speak of
Lines: 44
Message-ID: <87cytajwqe.fsf@nosuchdomain.example.com>
References: <upj3rq$da8$1@nyheter.lysator.liu.se>
<EP8vN.39265$Wbff.38272@fx37.iad>
<upjho8$hek$1@nyheter.lysator.liu.se>
<w3cvN.322279$c3Ea.250268@fx10.iad>
<upjmam$hek$2@nyheter.lysator.liu.se>
<87cytenve7.fsf@nosuchdomain.example.com>
<upmbnj$39vft$2@dont-email.me> <1bwmrkaoow.fsf@pfeifferfamily.net>
<qv52si5cvkajlf7fdcidur6elhism0u2su@dim53.demon.nl>
<upro72$g01t$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4718b0a0ab2e3c1c2260eb363d68ae7d";
logging-data="542211"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18IPMYJHZF2/oKl1xd0cJxq"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:c+far3uQNnZeC78rnvKOsMBTCt4=
sha1:/6ZAt0UwnlGsPdr4ESE4M1Onu1w=
 by: Keith Thompson - Mon, 5 Feb 2024 23:51 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Mon, 05 Feb 2024 18:22:59 +0100, Kees Nuyt wrote:
>> On Sat, 3 Feb 2024 21:37:55 -0000 (UTC), Lawrence D'Oliveiro wrote:
>> Signed characters make no sense.
>>
>> Nor did 6 bit characters, but in the 1980s we had them:
>> 3 characters in a 24 bit word.
>
> I see your sixbit and raise you Radix-50, which packed 3 characters into a
> 16-bit word.
>
> None of these used signed character codes, by the way. So my point still
> stands.

My understanding is that on the PDP-11, making plain char signed made
code that stored character values in int objects more efficient.
Sign-extension was more efficient than zero-filling or something like
that. I don't remember the details, but I'm sure it wouldn't be
difficult to find out.

At the time, making such code a little more efficient was worth the
effort -- and character data with the high-order bit set to 1 was rare,
so it didn't make much difference in practice.

I don't know whether there are efficiency issue on modern platforms. If
modern CPUs have similar characteristics to the PDP-11, that could
impose some pressure to keep signed characters. And the representation
requirements for the character types (especially with C23 requiring
2's-complement) mean that signed characters don't cause many practical
problems.

Since C code has always had to work correctly if plain char is signed,
there wasn't much pressure to make it unsigned (though some platforms do
so).

I'd be happy if some future C standard mandated that plain char is
unsigned, just because I think it would make more sense, but I don't
think that's likely to happen. But the historical reasons for allowing
plain char to be signed are valid.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor