code question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Bacarisse

    #46
    Re: code question

    CBFalconer <cbfalconer@yah oo.comwrites:
    Bill Cunningham wrote:
    >>
    >Someone pointed out to me Richard that an answer to a question I
    >raised about bitwise operators was on page 49 or kandr2. I read,
    >and re-read, and re-read page 49 about 3 times and strained to
    >keep my focus on reading and the text. The question was why is
    >the unary operator ~ shown like this:
    >>
    >x~34;
    >and not x=x~34;
    >>
    >Is the question indeed answered on that page?
    >
    Are you sure it is not "x ~= 34;"? Have you checked the published
    errata sheet? I greatly doubt that K&R have suppressed the blanks
    as you have.
    I think it is very unlikely that K&R made this mistake either with or
    without the spaces. I don't have K&R2 but since there is no published
    correction we can safely assume that Bill Cunningham is mistaken.

    In my K&R (1 not 2) the example is:

    ~ finds use in expressions such as

    x & ~077

    --
    Ben.

    Comment

    • Barry Schwarz

      #47
      Re: code question

      On Sat, 20 Sep 2008 00:47:34 -0400, CBFalconer <cbfalconer@yah oo.com>
      wrote:
      >Andrew Poelstra wrote:
      >Bill Cunningham <nospam@nspam.i nvalidwrote:
      >>
      >>Thanks Richard I know I can always count on you. I wondered about
      >>argc and its uses.
      >>
      >In addition to argc, argv is also NULL terminated (IIRC!), so
      >you can loop through it without needed argc to find out when
      >to stop.
      >>
      >while(*argv)
      >{
      > process(*argv);
      > ++argv;
      >}
      >
      >I'm not sure that is safe. Check whether argv[0] can be a NULL.
      Isn't that what the first line does?

      --
      Remove del for email

      Comment

      • Barry Schwarz

        #48
        Re: code question

        On Sat, 20 Sep 2008 00:50:59 -0400, CBFalconer <cbfalconer@yah oo.com>
        wrote:
        >Bill Cunningham wrote:
        >>
        >Someone pointed out to me Richard that an answer to a question I
        >raised about bitwise operators was on page 49 or kandr2. I read,
        >and re-read, and re-read page 49 about 3 times and strained to
        >keep my focus on reading and the text. The question was why is
        >the unary operator ~ shown like this:
        >>
        >x~34;
        >and not x=x~34;
        >>
        >Is the question indeed answered on that page?
        >
        >Are you sure it is not "x ~= 34;"? Have you checked the published
        >errata sheet? I greatly doubt that K&R have suppressed the blanks
        >as you have.
        Since there no character sequence "34" on page 49 (or 48 or 50) of K&R
        2 nor is there any character sequence "x~" (with or without
        intervening spaces), Bill's question makes even less sense than usual.
        I expect he is just guessing at the contents of the book the same way
        he guesses at the meaning of C constructs.

        --
        Remove del for email

        Comment

        • Barry Schwarz

          #49
          Re: code question

          On Fri, 19 Sep 2008 21:43:10 -0400, "Bill Cunningham"
          <nospam@nspam.i nvalidwrote:
          >
          >"Barry Schwarz" <schwarzb@dqel. comwrote in message
          >news:7fe8d4def 7j0qh98uumds7bt 8ae0635kvc@4ax. com...
          >On Fri, 19 Sep 2008 16:52:17 -0400, "Bill Cunningham"
          ><nospam@nspam. invalidwrote:
          >
          >> if ((fp = fopen(argv[4], "a")) == NULL) {
          >>
          >At the same time, it should be a file name.
          >>
          >That doesn't strike you as slightly odd?
          >>
          >A filename input is an argument. I thought you treated it as such. There are
          >many things that kandr2 doesn't teach you. Things like this for example.
          >That why clc is needed.
          Since you deliberately omitted the first half of the question, your
          response is completely irrelevant.

          However, it does offer additional proof that you are not the slightest
          bit interested in learning from the advice given here.

          --
          Remove del for email

          Comment

          • Default User

            #50
            Re: code question

            blargg wrote:
            In article <gb1lqt$m5j$3@r egistered.motza rella.org>,
            Richard<rgrdev@ gmail.comwrote:
            Amazing stuff. Really. If he's a troll (and I really think he is)
            then he's damn good.
            >
            And in a way, that makes him an excellent programmer of the wetware
            of the people who just can't help not responding to him, time after
            time after time.
            I don't know and I don't much care. Bill is either a troll, or has been
            "studying" C for at LEAST five years and made no more progress than
            this. If he's not a troll, then I don't see any reason to think that
            another five years or fifty years of CLC pouring out their advice will
            make the slightest difference.

            Replying to Bill is a waste of time one way or the other.




            Brian

            Comment

            • Richard Heathfield

              #51
              Re: code question

              Default User said:
              blargg wrote:
              >
              >In article <gb1lqt$m5j$3@r egistered.motza rella.org>,
              >Richard<rgrdev @gmail.comwrote :
              >
              Amazing stuff. Really. If he's a troll (and I really think he is)
              then he's damn good.
              >>
              >And in a way, that makes him an excellent programmer of the wetware
              >of the people who just can't help not responding to him, time after
              >time after time.
              >
              I don't know and I don't much care. Bill is either a troll, or has been
              "studying" C for at LEAST five years and made no more progress than
              this. If he's not a troll, then I don't see any reason to think that
              another five years or fifty years of CLC pouring out their advice will
              make the slightest difference.
              >
              Replying to Bill is a waste of time one way or the other.
              I agree that Bill Cunningham doesn't appear to gain any significant benefit
              from the responses he gets. Whether this is through malice or incompetence
              is really beside the point, and Hanlon's Razor applies.

              But his questions do sometimes provoke discussions that are likely to be of
              moderate interest to /other/ learners. If you think of a reply to one of
              Bill Cunningham's articles not as a reply to /him/, but as a reply to the
              points he has made, for general consumption, then it may perhaps seem
              slightly less of a Sisyphean task.

              --
              Richard Heathfield <http://www.cpax.org.uk >
              Email: -http://www. +rjh@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • Martien Verbruggen

                #52
                Re: code question

                On Sat, 20 Sep 2008 00:50:59 -0400,
                CBFalconer <cbfalconer@yah oo.comwrote:
                Bill Cunningham wrote:
                >>
                >Someone pointed out to me Richard that an answer to a question I
                >raised about bitwise operators was on page 49 or kandr2. I read,
                >and re-read, and re-read page 49 about 3 times and strained to
                >keep my focus on reading and the text. The question was why is
                >the unary operator ~ shown like this:
                >>
                >x~34;
                >and not x=x~34;
                >>
                >Is the question indeed answered on that page?
                >
                Are you sure it is not "x ~= 34;"? Have you checked the published
                errata sheet? I greatly doubt that K&R have suppressed the blanks
                as you have.
                I don't think Bill is saying that that question or that phrase appear on
                that page. I think he's saying that that was his question, and someone
                else told him that the answer to that could be found on page 49 of K&R2.

                Martien
                --
                |
                Martien Verbruggen | "In a world without fences,
                | who needs Gates?"
                |

                Comment

                • CBFalconer

                  #53
                  Re: code question

                  Barry Schwarz wrote:
                  CBFalconer <cbfalconer@yah oo.comwrote:
                  >Andrew Poelstra wrote:
                  >>Bill Cunningham <nospam@nspam.i nvalidwrote:
                  >>>
                  >>>Thanks Richard I know I can always count on you. I wondered
                  >>>about argc and its uses.
                  >>>
                  >>In addition to argc, argv is also NULL terminated (IIRC!), so
                  >>you can loop through it without needed argc to find out when
                  >>to stop.
                  >>>
                  >>while (*argv) {
                  >> process(*argv);
                  >> ++argv;
                  >>}
                  >>
                  >I'm not sure that is safe. Check whether argv[0] can be a NULL.
                  >
                  Isn't that what the first line does?
                  My point, which I haven't bothered to check, is that on some
                  systems argv[0] doesn't point to an identifier of the program. If
                  that is the case, is argv[0] value NULL, or does it point to an
                  empty string? If it is a NULL, the scanning sequence won't work.

                  --
                  [mail]: Chuck F (cbfalconer at maineline dot net)
                  [page]: <http://cbfalconer.home .att.net>
                  Try the download section.

                  Comment

                  • Richard

                    #54
                    Re: code question

                    CBFalconer <cbfalconer@yah oo.comwrites:
                    Barry Schwarz wrote:
                    >CBFalconer <cbfalconer@yah oo.comwrote:
                    >>Andrew Poelstra wrote:
                    >>>Bill Cunningham <nospam@nspam.i nvalidwrote:
                    >>>>
                    >>>>Thanks Richard I know I can always count on you. I wondered
                    >>>>about argc and its uses.
                    >>>>
                    >>>In addition to argc, argv is also NULL terminated (IIRC!), so
                    >>>you can loop through it without needed argc to find out when
                    >>>to stop.
                    >>>>
                    >>>while (*argv) {
                    >>> process(*argv);
                    >>> ++argv;
                    >>>}
                    >>>
                    >>I'm not sure that is safe. Check whether argv[0] can be a NULL.
                    >>
                    >Isn't that what the first line does?
                    >
                    My point, which I haven't bothered to check, is that on some
                    systems argv[0] doesn't point to an identifier of the program. If
                    What systems?

                    However IF the standard says that the first non existent argument slot
                    is NULL e.g

                    "myprog" then argv[1] is null then there really is not a problem if the
                    correct indices are used.

                    for(;*++argv;pr ocess(*argv));

                    Comment

                    • Ben Bacarisse

                      #55
                      Re: code question

                      CBFalconer <cbfalconer@yah oo.comwrites:
                      Barry Schwarz wrote:
                      >CBFalconer <cbfalconer@yah oo.comwrote:
                      >>Andrew Poelstra wrote:
                      >>>Bill Cunningham <nospam@nspam.i nvalidwrote:
                      >>>>
                      >>>>Thanks Richard I know I can always count on you. I wondered
                      >>>>about argc and its uses.
                      >>>>
                      >>>In addition to argc, argv is also NULL terminated (IIRC!), so
                      >>>you can loop through it without needed argc to find out when
                      >>>to stop.
                      >>>>
                      >>>while (*argv) {
                      >>> process(*argv);
                      >>> ++argv;
                      >>>}
                      >>>
                      >>I'm not sure that is safe. Check whether argv[0] can be a NULL.
                      >>
                      >Isn't that what the first line does?
                      >
                      My point, which I haven't bothered to check, is that on some
                      systems argv[0] doesn't point to an identifier of the program. If
                      that is the case, is argv[0] value NULL, or does it point to an
                      empty string? If it is a NULL, the scanning sequence won't work.
                      It might have been better to check. The code is fine. argv[0] can
                      only be NULL if argc == 0 in C90 and C99.

                      It is odd as it stands (because it processes a non-NULL argv[0] like
                      any other argument) but it is not wrong. It may, of course, be only a
                      fragment in which case it may not even be odd.

                      --
                      Ben.

                      Comment

                      • Barry Schwarz

                        #56
                        Re: code question

                        On Sat, 20 Sep 2008 18:23:00 -0400, CBFalconer <cbfalconer@yah oo.com>
                        wrote:
                        >Barry Schwarz wrote:
                        >CBFalconer <cbfalconer@yah oo.comwrote:
                        >>Andrew Poelstra wrote:
                        >>>Bill Cunningham <nospam@nspam.i nvalidwrote:
                        >>>>
                        >>>>Thanks Richard I know I can always count on you. I wondered
                        >>>>about argc and its uses.
                        >>>>
                        >>>In addition to argc, argv is also NULL terminated (IIRC!), so
                        >>>you can loop through it without needed argc to find out when
                        >>>to stop.
                        >>>>
                        >>>while (*argv) {
                        >>> process(*argv);
                        >>> ++argv;
                        >>>}
                        >>>
                        >>I'm not sure that is safe. Check whether argv[0] can be a NULL.
                        >>
                        >Isn't that what the first line does?
                        >
                        >My point, which I haven't bothered to check, is that on some
                        >systems argv[0] doesn't point to an identifier of the program. If
                        >that is the case, is argv[0] value NULL, or does it point to an
                        >empty string? If it is a NULL, the scanning sequence won't work.
                        Since 5.1.2.2.1 guarantees argc >= 0 and argv[argc] == NULL, the
                        situation you are concerned about cannot occur.

                        --
                        Remove del for email

                        Comment

                        • blargg

                          #57
                          Re: code question

                          In article <iq2dnbOB5dEc_0 jVnZ2dneKdnZydn Z2d@bt.com>,
                          Richard Heathfield <rjh@see.sig.in validwrote:
                          Default User said:
                          [...]
                          Replying to Bill is a waste of time one way or the other.
                          >
                          I agree that Bill Cunningham doesn't appear to gain any significant benefit
                          from the responses he gets. Whether this is through malice or incompetence
                          is really beside the point, and Hanlon's Razor applies.
                          >
                          But his questions do sometimes provoke discussions that are likely to be of
                          moderate interest to /other/ learners. If you think of a reply to one of
                          Bill Cunningham's articles not as a reply to /him/, but as a reply to the
                          points he has made, for general consumption, then it may perhaps seem
                          slightly less of a Sisyphean task.
                          Good point, but following it would mean answering his questions and not
                          replying further when he ignores the answer or mentions his copy of
                          "kandr2" from an alternate universe.

                          Comment

                          • Richard

                            #58
                            Re: code question

                            blargg <blargg.h4g@gis hpuppy.comwrite s:
                            In article <iq2dnbOB5dEc_0 jVnZ2dneKdnZydn Z2d@bt.com>,
                            Richard Heathfield <rjh@see.sig.in validwrote:
                            >
                            >Default User said:
                            [...]
                            Replying to Bill is a waste of time one way or the other.
                            >>
                            >I agree that Bill Cunningham doesn't appear to gain any significant benefit
                            >from the responses he gets. Whether this is through malice or incompetence
                            >is really beside the point, and Hanlon's Razor applies.
                            >>
                            >But his questions do sometimes provoke discussions that are likely to be of
                            >moderate interest to /other/ learners. If you think of a reply to one of
                            >Bill Cunningham's articles not as a reply to /him/, but as a reply to the
                            >points he has made, for general consumption, then it may perhaps seem
                            >slightly less of a Sisyphean task.
                            >
                            Good point, but following it would mean answering his questions and not
                            replying further when he ignores the answer or mentions his copy of
                            "kandr2" from an alternate universe.
                            Actually its not a good point at all. Primarily because Bill is yet to
                            ask a half decent question. He rarely if ever seems to know what he
                            wants leading to a rush of good Samaritans answering the question they
                            want it to be rather than the one he, supposedly, meant it to be.

                            Comment

                            • Default User

                              #59
                              Re: code question

                              Richard Heathfield wrote:
                              Default User said:
                              Replying to Bill is a waste of time one way or the other.
                              >
                              I agree that Bill Cunningham doesn't appear to gain any significant
                              benefit from the responses he gets. Whether this is through malice or
                              incompetence is really beside the point, and Hanlon's Razor applies.
                              >
                              But his questions do sometimes provoke discussions that are likely to
                              be of moderate interest to other learners. If you think of a reply to
                              one of Bill Cunningham's articles not as a reply to him, but as a
                              reply to the points he has made, for general consumption, then it may
                              perhaps seem slightly less of a Sisyphean task.
                              I'll freely admit that I still read through the threads, even though I
                              have Bill killfiled. Indeed, there's sometimes a useful nugget. Each
                              will have to make a decision on how to approach it.




                              Brian

                              Comment

                              • Richard Heathfield

                                #60
                                Re: code question

                                CBFalconer said:
                                Barry Schwarz wrote:
                                >CBFalconer <cbfalconer@yah oo.comwrote:
                                >>Andrew Poelstra wrote:
                                <snip>
                                >>>>
                                >>>while (*argv) {
                                >>> process(*argv);
                                >>> ++argv;
                                >>>}
                                >>>
                                >>I'm not sure that is safe. Check whether argv[0] can be a NULL.
                                >>
                                >Isn't that what the first line does?
                                >
                                My point, which I haven't bothered to check, is that on some
                                systems argv[0] doesn't point to an identifier of the program. If
                                that is the case, is argv[0] value NULL, or does it point to an
                                empty string? If it is a NULL, the scanning sequence won't work.
                                argv[0] is guaranteed *either* to represent the program name or to be NULL
                                (and argc to be 0), and the scanning sequence works fine whichever of
                                these is the case.

                                In future, please bother to check.

                                --
                                Richard Heathfield <http://www.cpax.org.uk >
                                Email: -http://www. +rjh@
                                Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                                "Usenet is a strange place" - dmr 29 July 1999

                                Comment

                                Working...