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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HTML_MESSAGE,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24101 invoked from network); 15 May 2020 20:25:34 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 15 May 2020 20:25:34 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id F1A199C97D; Sat, 16 May 2020 06:25:33 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 621A29C694; Sat, 16 May 2020 06:25:18 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=pass (1024-bit key; unprotected) header.d=ccc.com header.i=@ccc.com header.b="ineMh5dY"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 28A5C9C668; Sat, 16 May 2020 06:25:16 +1000 (AEST) Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by minnie.tuhs.org (Postfix) with ESMTPS id A184D9C668 for ; Sat, 16 May 2020 06:25:15 +1000 (AEST) Received: by mail-qk1-f177.google.com with SMTP id n14so3975210qke.8 for ; Fri, 15 May 2020 13:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccc.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=o3Qk0RMUSpLcrjSY8PUBGo4vg7k+aKSxDWK5nf/y8yo=; b=ineMh5dYR1Ar3+eqkTUFCqv+X8bRoXsPEqyRdgiWVRFkcJ8Y9+2Lu2mc/LX1kvn3nf Jyl4QdBLp9AfHWNz1xKBVjRNO1y1XHvNZZEWqoB3Z4dXyp0QLsrQpQOi5hAVhPkisX9m 5z1GKfLDsCUZuADcaBihnnMJjYjAGmmgktgAY= 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=o3Qk0RMUSpLcrjSY8PUBGo4vg7k+aKSxDWK5nf/y8yo=; b=XWTdq5omOHCPm2F6KvScLGTV+uEhMvmc/SkYlJovAf8nFy9PoCYfjLA8kfYb0RF//k W3I2ekw1WusakQBuksMfpCJV1pByZ73BFY/9oGXGsoW5KFSGhYOnOARYg4mIsHR8Pc41 H9Sb6NumDqllxu4I7jwwoU9+s6riH45xHsI9G1tKilHmpfNL4jPH0GOPghIFDE4wqrKX GtFsaSszCSEicLG0rnA7YBlfOtQPB0CV5y5B8fgEcaWsrfD21yTDayVWOk65lbNTQJgY prGj3bFDHbdNIOf01S7R3URfu4Mez4PkLnCwa2GywXKhMaX5z5pix05fezvBNs7x6Alk o1pA== X-Gm-Message-State: AOAM532xm3JTceOxSO84jMj0LaKz0NwVF69m6CtAyC3uB/m/MXzgqcAW xHTA6JrjUveUFQO2An8P6r3zwRC9ZTqqf1ezA44uDUE9 X-Google-Smtp-Source: ABdhPJzWSZdwjrSDIBh4B8I0ouS/ScGSMolaEoaVl0wnLNXkkLbcsQ7ElJ+WL1JdImvwdR5nA3WPtWFqqmDWd1pTQec= X-Received: by 2002:a37:a485:: with SMTP id n127mr5316554qke.476.1589574314639; Fri, 15 May 2020 13:25:14 -0700 (PDT) MIME-Version: 1.0 References: <202005141841.04EIfvEZ063529@tahoe.cs.Dartmouth.EDU> <20200515150122.GF30160@mcvoy.com> <014001d62af3$9cc209b0$d6461d10$@ronnatalie.com> <019701d62af6$050344b0$0f09ce10$@ronnatalie.com> In-Reply-To: <019701d62af6$050344b0$0f09ce10$@ronnatalie.com> From: Clem Cole Date: Fri, 15 May 2020 16:24:47 -0400 Message-ID: To: Ronald Natalie Content-Type: multipart/alternative; boundary="0000000000005e5ac405a5b59cf4" 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" --0000000000005e5ac405a5b59cf4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I suspect we are saying the same thing. C is defined as an int (as Larry also showed), not an unsigned char (and frankly if you had done that, most modern compilers will give you a warning). IIRC you are correct that the Ritchie compiler would not catch that error. But, the truth is I know few C (experienced) programmers that would define c as anything but an int; particularly in the modern era with compiler warnings as good as they are. Clem On Fri, May 15, 2020 at 4:18 PM wrote: > EOF is defined to be -1. > > getchar() returns int, but c is a unsigned char, the value of (c =3D > getchar()) will be 255. This will never compare equal to -1. > > > > > > > > Ron, > > > > Hmmm... getchar/getc are defined as returning int in the man page and C i= s > traditionally defined as an int in this code.. > > > > 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 re= cord is > now there */ > > > > --0000000000005e5ac405a5b59cf4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I suspect we are saying the same thing.=C2=A0 =C2=A0C i= s defined as an int (as Larry also showed), not an unsigned char (and frank= ly if you had done that, most modern compilers will give you a warning).=C2= =A0 IIRC you are correct that the Ritchie compiler would not catch that err= or.

But, the truth is I know few C (experienced) progr= ammers that would define c as anything but an int; particularly in the mode= rn era with compiler warnings as good as they are.

Cle= m

On Fri, May 15, 2020 at 4:18 PM <ron@ronnatalie.com> wrote:

EOF is defined to be -1.<= /u>

getchar() returns int, but c is a unsi= gned char, the value of (c =3D getchar()) will be 255.=C2=A0=C2=A0=C2=A0 Th= is will never compare equal to -1.

= =C2=A0

=C2=A0

=C2=A0

Ron,=C2=A0

=

= =C2=A0

Hmmm... getchar/getc are defined as returning i= nt in the man page and C is traditionally defined as an int in this code..<= u>

=C2=A0=

On Fri, May 15, 2020 at 4:02 PM &l= t;ron@ronnatalie.co= m> 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 detect= ed.

=C2=A0

=C2=A0=

=C2=A0

    =
  • while ((c =3D getchar()) !=3D EOF) if (c =3D=3D '\= n') { /* entire record is now there */

=C2=A0

--0000000000005e5ac405a5b59cf4--