function system() from stdlib.h

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Bos

    #31
    Re: function system() from stdlib.h

    CBFalconer <cbfalconer@yah oo.comwrote:
    Chris Dollin wrote:
    santosh wrote:
    Is there a specific reason for doing while( ... ) {} instead of
    while( ... ); other than readability? I consider the latter form
    to be more readable, but I may be in the minority regarding that.
    Readability. I find `;` to be more missable (and more likely to
    be an accident) than {}. One's parsecage may vary.
    >
    Try:
    >
    while (side_effects) continue;
    That's a good one; another I like is putting the semi-colon on a line of
    its own. That's unusual enough to be clear. Like this:

    while (side_effects--)
    ;

    Richard

    Comment

    • Chris Dollin

      #32
      Re: function system() from stdlib.h

      CBFalconer wrote:
      Chris Dollin wrote:
      >santosh wrote:
      >>
      ... snip ...
      >>>
      >>Is there a specific reason for doing while( ... ) {} instead of
      >>while( ... ); other than readability? I consider the latter form
      >>to be more readable, but I may be in the minority regarding that.
      >>
      >Readability. I find `;` to be more missable (and more likely to
      >be an accident) than {}. One's parsecage may vary.
      >
      Try:
      >
      while (side_effects) continue;
      I shan't /try/ it; while I can see that some would find it OK,
      it looks like an abomination to me. Of course what I'd /prefer/
      is `endwhile` [1] ... but C Is Not Built That Way And I Can't
      Change It.

      [1] Or `endrepeat`, as in `repeat A while B do C endrepeat`.

      --
      Chris "electric hedgehog" Dollin
      "- born in the lab under strict supervision -", - Magenta, /Genetesis/

      Comment

      • Keith Thompson

        #33
        Re: function system() from stdlib.h

        Chris Dollin <chris.dollin@h p.comwrites:
        CBFalconer wrote:
        [...]
        >Try:
        >>
        > while (side_effects) continue;
        >
        I shan't /try/ it; while I can see that some would find it OK,
        it looks like an abomination to me. Of course what I'd /prefer/
        is `endwhile` [1] ... but C Is Not Built That Way And I Can't
        Change It.
        Of course you can change it:

        #define endwhile }
        #define endif }
        ....

        (But don't expect anyone to read your code if you commit such an
        abomination.)

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
        We must do something. This is something. Therefore, we must do this.

        Comment

        • Richard Bos

          #34
          Re: function system() from stdlib.h

          Chris Dollin <chris.dollin@h p.comwrote:
          CBFalconer wrote:
          >
          Chris Dollin wrote:
          Readability. I find `;` to be more missable (and more likely to
          be an accident) than {}. One's parsecage may vary.
          Try:

          while (side_effects) continue;
          >
          I shan't /try/ it; while I can see that some would find it OK,
          it looks like an abomination to me. Of course what I'd /prefer/
          is `endwhile` [1] ... but C Is Not Built That Way And I Can't
          Change It.
          >
          [1] Or `endrepeat`, as in `repeat A while B do C endrepeat`.
          If you want to hack on the Bourne shell source, you know where to find
          it. Yuck.

          Richard

          Comment

          • Default User

            #35
            Re: function system() from stdlib.h

            Richard Bos wrote:
            CBFalconer <cbfalconer@yah oo.comwrote:
            >
            Chris Dollin wrote:
            santosh wrote:
            >
            >Is there a specific reason for doing while( ... ) {} instead of
            >while( ... ); other than readability? I consider the latter form
            >to be more readable, but I may be in the minority regarding that.
            >
            Readability. I find `;` to be more missable (and more likely to
            be an accident) than {}. One's parsecage may vary.
            Try:

            while (side_effects) continue;
            >
            That's a good one; another I like is putting the semi-colon on a line
            of its own. That's unusual enough to be clear. Like this:
            >
            while (side_effects--)
            ;
            The first C coding standard I worked under mandated/suggested that. It
            works pretty well, although these days I tend to use empty braces:

            while (side_effects--)
            {
            }



            Brian

            Comment

            • Simon Biber

              #36
              Re: function system() from stdlib.h

              Christopher Layne wrote:
              britzkrieg wrote:
              >
              >Hi,
              >>
              >I had write a program for Windows OS and put the following line:
              >>
              >system("pause" )
              >>
              >that use the "pause" command from DOS to pause the screen until I push
              >a button. How to get the same result in Linux's bash ?
              >>
              >thanks a lot
              >
              "read"
              >
              Literally:
              >
              #!/bin/bash
              read -p "press enter key when ready"
              <whatever else>
              >
              Now if it's a modern version of bash and you're commited to being bash
              specific:
              >
              read -s -n 1 -p "press any key when ready"
              >
              Silent echo, 1 char max
              If you want to exactly duplicate MS-DOS's pause command:

              system("read -s -n 1 -p \"Press any key to continue . . . \"; echo;");

              The extra echo command is necessary as pause adds a newline after you
              press a key.

              --
              Simon.

              Comment

              • Chris Dollin

                #37
                Re: function system() from stdlib.h

                Richard Bos wrote:
                Chris Dollin <chris.dollin@h p.comwrote:
                >
                >CBFalconer wrote:
                >>
                Chris Dollin wrote:
                >
                >Readability. I find `;` to be more missable (and more likely to
                >be an accident) than {}. One's parsecage may vary.
                >
                Try:
                >
                while (side_effects) continue;
                >>
                >I shan't /try/ it; while I can see that some would find it OK,
                >it looks like an abomination to me. Of course what I'd /prefer/
                >is `endwhile` [1] ... but C Is Not Built That Way And I Can't
                >Change It.
                >>
                >[1] Or `endrepeat`, as in `repeat A while B do C endrepeat`.
                >
                If you want to hack on the Bourne shell source, you know where to find
                it. Yuck.
                I don't. Why would you think I did?

                (Yes, I /know/ that the Bourne shell was writting with algolifying
                macros. C isn't built that way, and I can't change it, and I
                have no interest in trying to fake a better-according-to-me
                syntax using macros, for all the reasons behind your and
                Keith's expressions of distaste. To get a more pleasing grammar
                I go to -- or implement -- other languages.)

                --
                Chris "electric hedgehog" Dollin
                There' no hortage of vowel on Uenet.

                Comment

                • Richard Bos

                  #38
                  Re: function system() from stdlib.h

                  Chris Dollin <chris.dollin@h p.comwrote:
                  Richard Bos wrote:
                  >
                  Chris Dollin <chris.dollin@h p.comwrote:
                  CBFalconer wrote:
                  >
                  Try:

                  while (side_effects) continue;
                  >
                  I shan't /try/ it; while I can see that some would find it OK,
                  it looks like an abomination to me. Of course what I'd /prefer/
                  is `endwhile` [1] ... but C Is Not Built That Way And I Can't
                  Change It.
                  >
                  [1] Or `endrepeat`, as in `repeat A while B do C endrepeat`.
                  If you want to hack on the Bourne shell source, you know where to find
                  it. Yuck.
                  >
                  I don't. Why would you think I did?
                  If you want the origin for a standard hacker idiom, you know where to
                  find it.
                  (Yes, I /know/ that the Bourne shell was writting with algolifying
                  macros. C isn't built that way, and I can't change it, and I
                  have no interest in trying to fake a better-according-to-me
                  syntax using macros, for all the reasons behind your and
                  Keith's expressions of distaste.
                  No, you don't, because at least one of the reasons behind my distaste is
                  that I find the endrepeat grammar _not_ better, but overly voluble and
                  frequently less legible.

                  Richard

                  Comment

                  • Chris Dollin

                    #39
                    Re: function system() from stdlib.h

                    Richard Bos wrote:
                    Chris Dollin <chris.dollin@h p.comwrote:
                    >
                    >Richard Bos wrote:
                    >>
                    Chris Dollin <chris.dollin@h p.comwrote:
                    >
                    >CBFalconer wrote:
                    >>
                    Try:
                    >
                    while (side_effects) continue;
                    >>
                    >I shan't /try/ it; while I can see that some would find it OK,
                    >it looks like an abomination to me. Of course what I'd /prefer/
                    >is `endwhile` [1] ... but C Is Not Built That Way And I Can't
                    >Change It.
                    >>
                    >[1] Or `endrepeat`, as in `repeat A while B do C endrepeat`.
                    >
                    If you want to hack on the Bourne shell source, you know where to find
                    it. Yuck.
                    >>
                    >I don't. Why would you think I did?
                    >
                    If you want the origin for a standard hacker idiom, you know where to
                    find it.
                    That's not an answer.
                    >(Yes, I /know/ that the Bourne shell was writting with algolifying
                    > macros. C isn't built that way, and I can't change it, and I
                    > have no interest in trying to fake a better-according-to-me
                    > syntax using macros, for all the reasons behind your and
                    > Keith's expressions of distaste.
                    >
                    No, you don't, because at least one of the reasons behind my distaste is
                    that I find the endrepeat grammar _not_ better, but overly voluble and
                    frequently less legible.
                    Ah. Well, it would have helped if you'd said that. Usually when
                    I've seem people yuck over the Bourne shell its the algolification-
                    via-macros that's the issue, not the intended syntax. (I'm curious
                    whether you've seen a language with the repeat-endrepeat syntax,
                    since the one I know it from is Pop11.)

                    Grammatical tastes differ.

                    Um, this is barely topical: if you're bothered to respond, I'll
                    take email.

                    --
                    Chris "electric hedgehog" Dollin
                    "He's dead, Jim, but not as we know it." Unsaid /Trek/.

                    Comment

                    Working...