Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If Machiavelli were a hacker, he'd have worked for the CSSG. -- Phil Lapsley


devel / comp.lang.c / Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''

SubjectAuthor
* K&R, 2nd edition, Brian's concerns with ``char c = EOF''Meredith Montgomery
+* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
|+* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Meredith Montgomery
||`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
|| +- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Meredith Montgomery
|| `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Scott Lurndal
|`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Philipp Klaus Krause
| `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
|  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Philipp Klaus Krause
|   `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
|    `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Philipp Klaus Krause
|     `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Tim Rentsch
|      `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''David Brown
+* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Barry Schwarz
|+- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Meredith Montgomery
|`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''David Brown
| `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Meredith Montgomery
+- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Mark Bluemel
+* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Mark Bluemel
|`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
| +- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Mark Bluemel
| `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Malcolm McLean
|  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
|   `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Scott Lurndal
+* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
|`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
| +* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
| |`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
| | +* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Tim Rentsch
| | |`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
| | | +- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Manfred
| | | +* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Ben Bacarisse
| | | |`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Bart
| | | | +* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
| | | | |`- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Ben Bacarisse
| | | | `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Ben Bacarisse
| | | |  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Bart
| | | |   `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Ben Bacarisse
| | | `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Tim Rentsch
| | |  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Keith Thompson
| | |   `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Tim Rentsch
| | +* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Paul
| | |`- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Chris M. Thomasson
| | `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''luser droog
| |  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
| |   +- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Manfred
| |   +- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Bart
| |   `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Tim Rentsch
| `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Mark Bluemel
|  `* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Bart
|   `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Dave Dunfield
+- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Andrey Tarasevich
`* Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''Kaz Kylheku
 `- Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''James Kuyper

Pages:123
Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''

<865yrt7pzy.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19370&group=comp.lang.c#19370

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''
Date: Sun, 12 Dec 2021 08:21:53 -0800
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <865yrt7pzy.fsf@linuxsc.com>
References: <86pmqwkm7u.fsf@levado.to> <4fcda596-2e00-4dd6-bf8f-4616218f4398n@googlegroups.com> <91a56855-b917-45a2-89be-7e2ed806d357n@googlegroups.com> <87a6hac0oj.fsf@nosuchdomain.example.com> <11efb602-293a-4a90-b0bd-832617377f57n@googlegroups.com> <86fsr28ns3.fsf@linuxsc.com> <5e1ba862-156c-4b1d-93a4-661ef66aadedn@googlegroups.com> <86lf0s7pcy.fsf@linuxsc.com> <875yrwb8mi.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="52dee2417da2788e9c7fc8c78c748ef1";
logging-data="30669"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197jIsg17Hl81SFm+V0cBFkTsQGsY8JUIc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:SiCzR5+JXpddjm9a8WkDVGHFXVQ=
sha1:eZdEa30/dM/H1S/OI7eTMEdlapA=
 by: Tim Rentsch - Sun, 12 Dec 2021 16:21 UTC

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

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Dave Dunfield <dave.dunfield@gmail.com> writes:
>>
>>> On Wednesday, December 8, 2021 at 10:23:22 PM UTC-5, Tim Rentsch wrote:
>>>
>>>> (Incidentally, can you explain why you can't set up a news
>>>> account with one of several few news providers, such as
>>>> eternal-september, and avoid the problems of using google
>>>> groups?)
>>>
>>> Just haven't taken the time so far ... looked into setting up some
>>> sort of newsgroup access and spent hours running into various
>>> roadblocks... Along the way I discovered "Google Groups" which
>>> would give me access with little difficulty .. just at the cost of
>>> having everything reformatted in a "code unfriendly" manner...
>>
>> If you want other people to look at what you're doing it's
>> important to provide access in a way that _they_ think is easy.
>>
>>> [...] I've essentially retired and having much more time on my
>>> hands, [...]
>>
>> If you have lots of free time, you might practice writing C code
>> that conforms to the ISO C standard. Good feedback is available
>> using
>>
>> gcc -std=c99 -pedantic-errors
>
> If you have a reasonably modern version of gcc, you can use -std=c11 or
> -std=c17. (C17 was a minor update on top of C11, and the only
> difference between gcc's -std=c11 and -std=c17 options is the value of
> __STDC_VERSION__.)

I deliberately chose C99 because I think it's the best fit
for the suggestion given.

Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''

<20211212091034.341@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19375&group=comp.lang.c#19375

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''
Date: Sun, 12 Dec 2021 18:55:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20211212091034.341@kylheku.com>
References: <86pmqwkm7u.fsf@levado.to>
Injection-Date: Sun, 12 Dec 2021 18:55:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a3c9bb97468a88efb6370e2c2dacfe7d";
logging-data="19353"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bvj8IO0KFLehtKuglAwVma+/NtN9AShA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:c5TJ2ENxnMP1UXw4n+eQ0JWa+BU=
 by: Kaz Kylheku - Sun, 12 Dec 2021 18:55 UTC

On 2021-11-19, Meredith Montgomery <mmontgomery@levado.to> wrote:
> I did not get Brian Kernighan's concern with setting EOF to a char c.
> The context is
>
> char c = getchar();
>
> And Kernighan says:
>
> --8<---------------cut here---------------start------------->8---
> We must declare c to be a type big enough to hold any value that getchar
> returns. We can't use char since c must be big enough to hold EOF in
> addition to any possible char . Therefore we use int.
> --8<---------------cut here---------------end--------------->8---

Not all of this is correct. The conclusion to use int is correct,
but it is incorrect to insinuate that:

- EOF is distinct from values of char (it isn't required to be,
and quite often isn't: char is often signed, and EOF is often #defined
as -1).

- getchar() returns values of char (it doesn't; if a datum is available
from the stream, it returns it as a value from 0 to UCHAR_MAX).

Is the quote verbatim?

Also, the primary reason to capture the return value of getchar, getc
and fgetc using a value of type int is that this is the declared
return type of these functions.

If a function returns int, you capture that with int, or else (if
you have special reasons for it) an integer type whose range is a
superset of int. Your choice need not, and ideally should not, be
justified with the run-time semantics of the function; you know
from the type that you're capturing every value.

(To handle the value futher, you have to know something about its
semantics, like which subset of its range represents a datum and which
value(s) are in-band error signaling.)

> So I can't be sure a char would always be signed, for example. I can't
> be sure EOF would fit in a char.

It is overwhelmingly common for EOF to have a value that is
representable in a char (informally, to "fit" into a char).

And that would be a problem if getchar returned char values,
and one not solved by the int return type.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''

<sp5j3l$47q$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19376&group=comp.lang.c#19376

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''
Date: Sun, 12 Dec 2021 14:38:28 -0500
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <sp5j3l$47q$1@dont-email.me>
References: <86pmqwkm7u.fsf@levado.to> <20211212091034.341@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Dec 2021 19:38:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f9db4e4c4e73dc06e9c6170ccc8f0b1a";
logging-data="4346"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19abhfnHY9kyshEGB0Nopl/WQbzG+jeXS0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:Bx12pUoCXlmVJG67OA2PP2xr3wk=
In-Reply-To: <20211212091034.341@kylheku.com>
Content-Language: en-US
 by: James Kuyper - Sun, 12 Dec 2021 19:38 UTC

On 12/12/21 1:55 PM, Kaz Kylheku wrote:
....
> Not all of this is correct. The conclusion to use int is correct,
> but it is incorrect to insinuate that:
>
> - EOF is distinct from values of char (it isn't required to be,
> and quite often isn't: char is often signed, and EOF is often #defined
> as -1).

You're quite correct that EOF isn't required to be distinct from valid
values - but it's also much more convenient if it is distinct. I think
you'll find that systems where char is signed are generally also systems
where EOF != -1.

The implementations where there's a real problem are those where it's
not possible for EOF to be a distinct value. For example, that would be
the case if UCHAR_MAX > INT_MAX (which requires that CHAR_BIT >= 16).

All standard I/O is defined as behaving as if it ultimately involves
calls to fputc() or fgetc(). fputc() is defined as converting from int
to unsigned char; fgetc() is defined as reversing that conversion. In
general, conversion a value that's too large to be represented in the
new type either produces an implementation-defined result, or raises an
implementation-defined signal.

However, "Data read in from a binary stream shall compare equal to the
data that were earlier written out to that stream, under the same
implementation." Therefore, if you call fputc(EOF, binary_stream), a
call to fgetc() which reads that byte must return EOF, without actually
being at the end of a file. This is true, regardless of which value the
implementation chooses for EOF. On such systems, you must check feof()
and ferr() to determine whether eis

> - getchar() returns values of char (it doesn't; if a datum is available
> from the stream, it returns it as a value from 0 to UCHAR_MAX).

It's read in as unsigned char, but converted to int; in the unlikely
event that UCHAR_MAX > INT_MAX, that conversion will change the value.

>> So I can't be sure a char would always be signed, for example. I can't
>> be sure EOF would fit in a char.
>
> It is overwhelmingly common for EOF to have a value that is
> representable in a char (informally, to "fit" into a char).

Not on systems where char is unsigned.

Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''

<86zgp246c8.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19411&group=comp.lang.c#19411

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: K&R, 2nd edition, Brian's concerns with ``char c = EOF''
Date: Wed, 15 Dec 2021 00:31:35 -0800
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <86zgp246c8.fsf@linuxsc.com>
References: <86pmqwkm7u.fsf@levado.to> <4fcda596-2e00-4dd6-bf8f-4616218f4398n@googlegroups.com> <91a56855-b917-45a2-89be-7e2ed806d357n@googlegroups.com> <87a6hac0oj.fsf@nosuchdomain.example.com> <11efb602-293a-4a90-b0bd-832617377f57n@googlegroups.com> <ffd6cd65-e491-430b-88ac-93869d57e8e0n@googlegroups.com> <abb6f4ef-5f74-470c-b9a3-6b296ced4e71n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="87e29f815fda23c6ea6c6dd22211e8ad";
logging-data="12712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CR/wgm8/9xqsMWQcX60yzTFZNyDYGSxA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:n1kBdS28xUFDGzBEkvk40BoRZes=
sha1:HTZp30mQxWauR/vhkAHdidhQ204=
 by: Tim Rentsch - Wed, 15 Dec 2021 08:31 UTC

Dave Dunfield <dave.dunfield@gmail.com> writes:

> [...]

For future reference here is a short C program that does
base64 encoding.

/*** b64e.c - base64 encode stdin to stdout. */
/*** NOTE: This program assumes characters are 8 bits. */

#include <stdio.h>

static char A[] = {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
};

int
main( void ){
int c;
unsigned long b = 0, n = 0, k = 0;
char out[ 73 ];

while( c = getchar(), c != EOF ){
b = (b<<8) + c, n += 8;
do {
if( k > 71 ) out[k] = 0, puts( out ), k = 0;
n -= 6;
out[ k++ ] = A[ b >>n &63 ];
} while( n > 5 );
}

if( n > 0 ) out[ k++ ] = A[ b <<(6-n) &63 ];

if( k > 0 ) out[k] = 0, puts( out ), k = 0;
else puts( "====" );

return 0;
}

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor