Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #112512

Re: What is the difference between (r+ and w+)

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: What is the difference between (r+ and w+)
Date 2017-06-19 00:16 +0100
Organization A noiseless patient Spider
Message-ID <87zid43n05.fsf@bsb.me.uk> (permalink)
References (3 earlier) <oi4l0m$vl6$1@jstuckle.eternal-september.org> <oi4mab$a0f$1@gioia.aioe.org> <oi4p0m$8on$1@dont-email.me> <87h8zd4d9n.fsf@bsb.me.uk> <oi63gm$odt$1@dont-email.me>

Show all headers | View raw


Richard Heathfield <rjh@cpax.org.uk> writes:

> On 18/06/17 14:49, Ben Bacarisse wrote:
>> Richard Heathfield <rjh@cpax.org.uk> writes:
>>
>>> On 18/06/17 02:50, Christopher wrote:
>> <snip>
>>>> <https://drive.google.com/file/d/0Bwx0lG_v1tcONExSejZWMGJaMUU/view?usp=sharing>
>>>
>>> The "Hot Tip" is wrong. The stdio.h header contains no functions at
>>> all.
>>
>> How do you know that stdio.h contains no functions at all?
>
<snip>
> If we're talking about the standard stdio.h it has to work in the
> following situation:
>
> /* a.c */
> #include <stdio.h>
>
> int foo(FILE *);
> int main(void)
> {
>   foo(stdin);
>   return 0;
> }
>
> /* b.c */
> #include <stdio.h>
>
> void foo(FILE *fp)
> {
>   char line[128];
>   while(fgets(line, sizeof line, fp) != NULL)
>   {
>     fputs(line, stdout);
>   }
> }
>
> Now, if <stdio.h> contains a function (as opposed to a function
> declaration or a function prototype), EITHER the above program will
> not link (because there are now two definitions of the same function),
> OR the implementers have gone to unnecessary preprocessor-directive
> lengths to detect whether to incorporate the function in the
> translation unit or not.

What about static inline functions?

>>> (Nor is stdio.h necessarily a file, and this assumption appears
>>> in the first sentence of the main text as well, and indeed throughout
>>> the quoted text.)
>>
>> A quote from K&R2:
>>
>>   A.12.4 File Inclusion
>>
>>   A control line of the form
>>     # include <filename>
>>   causes the replacement of that line by the entire contents of the
>>   file filename.
>
> Then K&R were also guilty of an unjustifiable assumption. Their error may or may not be excusable because the Standard was so new at that time, but a book written in 2012, more than two decades after the text of the Standard became available, certainly cannot claim that excuse.
>
>> <snip>
>>> The third paragraph introduces a
>>> definitely false claim in its first sentence (the claim that fopen()
>>> must always be used to open files),
>>
>> Another quote from K&R2:
>>
>>   Before it can be read or written, a file has to be opened by the
>>   library function fopen."
>
> stdin, stdout, and stderr are all counter-examples. Also:
>
> if(freopen("myfile.dat", "rb", stdin) != NULL)

I know.  The point is not what is right but that K&R make the same
simplifications for explanatory purposes.

<snip>
>>> Using printf instead of fprintf to display diagnostic information is poor style.
>>
>> Another K&R2 quote, this time from an example program:
>>
>>   if (op2 != 0.0)
>>       push(pop() / op2);
>>   else
>>       printf("error: zero divisor\n");
>
> Yes, that's poor style unless there are compelling reasons to consider error messages to be part of the program's normal output.
>
> fprintf(stderr, "error: zero divisor\n");
>
> is far preferable.

Yes, I know.  I did not intend that you you go thought the remarks you
made and make them again.

>>> This:
>>>
>>> int func(void)
>>> {
>>>   if(this)
>>>   {
>>>     return such-and-such;
>>>   }
>>>   else
>>>   {
>>>     return something-else;
>>>   }
>>> }
>>>
>>> is legal, but it's so much cleaner to return an int at the function
>>> body level:
>>
>> And int K&R2 we find:
>>
>>   /* lower: convert c to lower case; ASCII only */
>>   int lower(int c)
>>   {
>>       if (c >= 'A' && c <= 'Z')
>>           return c + 'a' - 'A';
>>       else
>>           return c;
>>   }
>>
>> <snip>
>>> and good habits are best taught early.
>>
>> After reading K&R, yes?
>
> You are making out a fairly compelling case for K&R /not/ to be used
> to teach good habits.

Is that your conclusion?  I'm fine with it for experienced programmers
and I've never though it suitable for beginners.

>> <snip>
>>> The use of 1 rather than EXIT_FAILURE is non-portable.
>>
>>   /* find all lines matching pattern */
>>   main()
>>   {
>>       char line[MAXLINE];
>>       int found = 0;
>>       while (getline(line, MAXLINE) > 0)
>>           if (strindex(line, pattern) >= 0) {
>>               printf("%s", line);
>>               found++;
>>           }
>>       return found;
>>   }
>>
>> (no guesses as to where that's from).
>
> I can't imagine. :-) But my answer is the same. That's a very Unixy
> way of looking at C.
>>
>>> Finally, the failure to pass any diagnostic flags *at all* to gcc is
>>> worrying.
>>
>>   "compile it with the command
>>   cc hello.c"
>>
>> (Yes, K&R2 again.)
>
> The world has moved on.

Sure.  The /reason/ is not so much the point as that we are in peril of
not having any book to recommend.

>> Have people called out K&R for all these things?
>
> Have people's attention been drawn to all these things?
>
>> If not, there's more
>> than a whiff of a double standard here.
>
> Or nobody looked before (with this particular set of questions in
> mind).

That seems unlikely, but I accept that it may be so.

<snip>
> You have raised less than a dozen issues with K&R, scattered through
> the whole book. The points I raised regarding "C Programming in Easy
> Steps" all occurred on just two pages, which suggests a significantly
> greater error density.

Oh sure.  The bottom line is what should someone starting out read if
they want to learn C?

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is the difference between (r+ and w+) Christopher <invalid@invalid.invalid> - 2017-06-17 23:59 -0100
  Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-17 17:51 -0700
    Re: What is the difference between (r+ and w+) Christopher <invalid@invalid.invalid> - 2017-06-18 00:00 -0100
      Re: What is the difference between (r+ and w+) Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-17 21:32 -0400
        Re: What is the difference between (r+ and w+) Christopher <invalid@invalid.invalid> - 2017-06-18 00:50 -0100
          Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 03:40 +0100
            Re: What is the difference between (r+ and w+) jacobnavia <jacob@jacob.remcomp.fr> - 2017-06-18 11:48 +0200
              Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 13:13 +0100
                Re: What is the difference between (r+ and w+) Gareth Owen <gwowen@gmail.com> - 2017-06-18 16:20 +0100
            Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-18 14:49 +0100
              Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 15:46 +0100
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-19 00:16 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-19 05:37 +0100
                Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-19 09:25 -0700
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-19 17:35 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-19 18:19 +0100
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-19 20:51 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-19 21:16 +0100
                Re: What is the difference between (r+ and w+) Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-19 04:58 -0700
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-19 17:43 +0100
                Re: What is the difference between (r+ and w+) Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-19 22:16 -0700
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-20 11:53 +0100
                Re: What is the difference between (r+ and w+) Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-20 22:45 -0700
              Re: What is the difference between (r+ and w+) Good Guy <hello.world@example.com> - 2017-06-18 18:17 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 18:20 +0100
                Re: What is the difference between (r+ and w+) bartc <bc@freeuk.com> - 2017-06-18 18:27 +0100
                Re: What is the difference between (r+ and w+) jacobnavia <jacob@jacob.remcomp.fr> - 2017-06-20 11:11 +0200
                Re: What is the difference between (r+ and w+) bartc <bc@freeuk.com> - 2017-06-20 10:27 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-20 10:54 +0100
                Re: What is the difference between (r+ and w+) jacobnavia <jacob@jacob.remcomp.fr> - 2017-06-20 12:25 +0200
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-20 12:34 +0100
                Re: What is the difference between (r+ and w+) jameskuyper@verizon.net - 2017-06-20 05:37 -0700
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-20 14:11 +0100
                Re: What is the difference between (r+ and w+) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-20 14:35 +0100
                Re: What is the difference between (r+ and w+) raltbos@xs4all.nl (Richard Bos) - 2017-06-18 17:30 +0000
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 21:21 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 21:23 +0100
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 21:47 +0100
                Re: What is the difference between (r+ and w+) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-18 17:01 -0400
                Re: What is the difference between (r+ and w+) "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-19 10:41 -0400
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 21:50 +0100
                Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-18 13:52 -0700
                Re: What is the difference between (r+ and w+) jacobnavia <jacob@jacob.remcomp.fr> - 2017-06-20 11:16 +0200
                Re: What is the difference between (r+ and w+) raltbos@xs4all.nl (Richard Bos) - 2017-06-26 15:54 +0000
                Re: What is the difference between (r+ and w+) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-18 17:13 -0400
                Re: What is the difference between (r+ and w+) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-18 17:17 -0400
                Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-18 15:14 -0700
                Re: What is the difference between (r+ and w+) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-06-18 18:24 -0400
                Re: What is the difference between (r+ and w+) Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-19 04:11 -0700
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 23:01 +0100
          Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-17 19:55 -0700
            Re: What is the difference between (r+ and w+) Christopher <invalid@invalid.invalid> - 2017-06-18 02:10 -0100
              Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 04:15 +0100
              Re: What is the difference between (r+ and w+) raltbos@xs4all.nl (Richard Bos) - 2017-06-18 08:31 +0000
                Re: What is the difference between (r+ and w+) Good Guy <hello.world@example.com> - 2017-06-18 18:28 +0100
                Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-18 11:25 -0700
                Re: What is the difference between (r+ and w+) raltbos@xs4all.nl (Richard Bos) - 2017-06-18 19:13 +0000
                Re: What is the difference between (r+ and w+) David Kleinecke <dkleinecke@gmail.com> - 2017-06-18 14:30 -0700
                Re: What is the difference between (r+ and w+) Richard Heathfield <rjh@cpax.org.uk> - 2017-06-18 23:04 +0100
              Re: What is the difference between (r+ and w+) GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-18 10:43 +0200
                Re: What is the difference between (r+ and w+) Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-18 10:33 -0400
                Re: What is the difference between (r+ and w+) GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-06-19 01:27 +0200
                Re: What is the difference between (r+ and w+) Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-18 21:16 -0400
      Re: What is the difference between (r+ and w+) Ian Collins <ian-news@hotmail.com> - 2017-06-18 13:45 +1200
      Re: What is the difference between (r+ and w+) Keith Thompson <kst-u@mib.org> - 2017-06-17 19:05 -0700

csiph-web