From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8532 invoked from network); 16 May 2020 17:40:42 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 16 May 2020 17:40:42 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id B7CF59C5FC; Sun, 17 May 2020 03:40:39 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id ACDA39C5E5; Sun, 17 May 2020 03:40:09 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (2048-bit key; unprotected) header.d=bsdimp-com.20150623.gappssmtp.com header.i=@bsdimp-com.20150623.gappssmtp.com header.b="ItcuQZs1"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 35D649C5E5; Sun, 17 May 2020 03:40:07 +1000 (AEST) Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by minnie.tuhs.org (Postfix) with ESMTPS id 8C3A39C5E4 for ; Sun, 17 May 2020 03:40:06 +1000 (AEST) Received: by mail-qt1-f180.google.com with SMTP id m44so4737485qtm.8 for ; Sat, 16 May 2020 10:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+wQjXM5IX72b7hq3ujcpX8Am3AzHsimljkU95v2Rq0M=; b=ItcuQZs1TNVr3+6qFgw+grUvGdyYzODgcfWZmwkqtUBtSKT3Q9tw+DTV5P4m59EfCU X9c/vPFo5sS9A/eclx0ZwFuB1JaQLbBxd6rU75AcGhE2fV9auJoDCiG1KA+QZHigkhtC Ss6DDUfRtxRpAOKEZQcGCZNDS56LaV4qRG8ZAHI6CUCKRoX3clhvyUGcHKpBqboJz+1a MGzl2nI3YLxELIljGlAXJMWrFh+VracvRfqGtcq1EhxYCcSoTD3c3peYBL2oeQBAtcXX sWS8jYif/ixEofyPMJ08hYkPCVZavQgbSV504hOmRcr7ybNPcLHZB3J0KvFxyFX20IfG xC6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+wQjXM5IX72b7hq3ujcpX8Am3AzHsimljkU95v2Rq0M=; b=D09HSTf/+M/IBVTV2xT1DsXqIGfWcJsE0W0RE6G2eADy3B7w7Ll/9fZlSuCJPf5rZb xZh18z4nfQzQE4QtewRXS8N+XdPt0GyiBCw1mg3fJPw9CMo4KJ0g0WTbeIpWo0IOqfoX 9QvPD+52eT7hbZdE+XiTYgwfoFMKVUX8Im0ZBC9pbS2ywrLCI2vgJtbQGeKwBuK0vqij tWG1Y8fwasz8IdmzWg7ZyMXIRS2w/LPACYs7DZgFViu3Y04iYPTQYsif9d2JTCt/205b uep8OPFIPHr1lHUZiMzvSO5KfTE1Q3UztoItntC/eov0LP8WhtHT5+cF8iKkQ8rs41x1 r+zw== X-Gm-Message-State: AOAM531l61QPp6OvQQKEOJBX5uYaZ27xLCPVMYTr4DZMRFKjugFKzRkT EcU20NLigh8MfS2qVcP0gJ/LlCeOLaPY690R5xM1gRiwTlw= X-Google-Smtp-Source: ABdhPJz5zvPBk5YCn89QGF1xnG5wUKTDMj14Qmjf44LQaynMaV8l0cdQG3irVL9K7yGal+1s8Y6LQwENTaB3Bi+WG8E= X-Received: by 2002:aed:3185:: with SMTP id 5mr9102494qth.187.1589650805555; Sat, 16 May 2020 10:40:05 -0700 (PDT) MIME-Version: 1.0 References: <202005141841.04EIfvEZ063529@tahoe.cs.Dartmouth.EDU> <20200515150122.GF30160@mcvoy.com> <014001d62af3$9cc209b0$d6461d10$@ronnatalie.com> In-Reply-To: From: Warner Losh Date: Sat, 16 May 2020 11:39:54 -0600 Message-ID: To: Paul Winalski Content-Type: multipart/alternative; boundary="0000000000009519f805a5c76bef" Subject: Re: [TUHS] v7 K&R C X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The Eunuchs Hysterical Society Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" --0000000000009519f805a5c76bef Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, May 16, 2020 at 10:28 AM Paul Winalski wrote: > > On Fri, May 15, 2020 at 4:02 PM wrote: > > > >Unfortunately, if c is char on a machine with unsigned chars, or it=E2= =80=99s of > >type unsigned char, the EOF will never be detected. > > > > - while ((c =3D getchar()) !=3D EOF) if (c =3D=3D '\n') { /* entire = record is > now there */ > > The function prototype for getchar() is: int getchar(void); > > It returns an int, not a char. In all likelihood this is specifically > *because* EOF is defined as -1. The above code works fine if c is an > int. One always has to be very careful when doing a typecast of a > function return value. > In the early days of my involvement with FreeBSD, I went through and fixed about a dozen cases where getopt was being assigned to a char and then compared with EOF. I'm certain that this is why. Also EOF has to be a value that's not representable by a character, or your 0xff bytes would disappear= . Warner --0000000000009519f805a5c76bef Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Sat, May 16, 2020 at 10:28 AM Paul= Winalski <paul.winalski@gmai= l.com> wrote:
> On Fri, May 15, 2020 at 4:02 PM <ron@ronnatalie.com> wrote:
>
>Unfortunately, if c is char on a machine with unsigned chars, or it=E2= =80=99s of
>type unsigned char, the EOF will never be detected.
>
>=C2=A0 =C2=A0 - while ((c =3D getchar()) !=3D EOF) if (c =3D=3D '\n= ') { /* entire record is now there */

The function prototype for getchar() is:=C2=A0 =C2=A0 int getchar(void);
It returns an int, not a char.=C2=A0 In all likelihood this is specifically=
*because* EOF is defined as -1.=C2=A0 The above code works fine if c is an<= br> int.=C2=A0 One always has to be very careful when doing a typecast of a
function return value.

In the early day= s of my involvement with FreeBSD, I went through and fixed about a dozen ca= ses where getopt was being assigned to a char and then compared with EOF. I= 'm certain that this is why. Also EOF has to be a value that's not = representable by a character, or your 0xff bytes would disappear.

Warner=C2=A0
--0000000000009519f805a5c76bef--