for(;0;) printf("hello");

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

    #46
    Re: for(;0;) printf("he llo");


    Spidey wrote:
    for(;0;)
    printf("hello") ;
    >
    even the condition s wrong i get a hello printed on the screen
    y s this happening
    this could happen if some malicious person went into your stdio.h file
    (which you probably included but didnt show) and they added a line
    something like: #define for(x).

    Either that or the compiler is incorrectly optimizing the code and
    somehow falling thru the code the first time.

    Comment

    • Michael Wojcik

      #47
      Re: for(;0;) printf("he llo");


      In article <1157905584.803 527.231760@m79g 2000cwm.googleg roups.com>, "Spiros Bousbouras" <spibou@gmail.c omwrites:
      Keith Thompson wrote:
      >
      Richard Heathfield <invalid@invali d.invalidwrites :
      [...]
      Gv th mn a bnn!
      Give the man a bunny?
      >
      Banana !
      And here I was sure it was "bunion".

      --
      Michael Wojcik michael.wojcik@ microfocus.com

      Comment

      • jmcgill

        #48
        Re: for(;0;) printf(&quot;he llo&quot;);

        Chris Dollin wrote:
        jmcgill wrote:
        >
        >Brackets are not only proper syntax, they are also a good idea. They
        >are anything but "clutter."
        >
        Opinions differ.
        >
        They're certainly proper syntax. Sometimes they are also necessary.
        Appendectomies are also sometimes necessary.
        Putting braces around statements does not cause you to lose your appendix.

        Comment

        • bart.kowalski@gmail.com

          #49
          Re: for(;0;) printf(&quot;he llo&quot;);

          Richard Heathfield wrote:
          jmcgill said:
          >
          Simon Biber wrote:
          for(;0;)
          printf("hello") ;
          Would it kill you to use curly braces?
          >
          Since a parallel reply responds negatively to your suggestion, I thought you
          might welcome some support for your position.
          >
          Strange as it may seem, not everyone is an expert C programmer. A
          maintenance guy in a hurry, confronted with this code:
          >
          for(image = 0; image < numimages - 1; image++)
          for(y = 0; y < height; y++)
          for(x = 0; x < width; x++)
          if(img[image].pixel[y][x] & ALPHA)
          img[image].pixel[y][x] =
          alpha_blend(img[image].pixel[y][x],
          img[image + 1].pixel[y][x],
          img[image].alpha);
          >
          could be forgiven for adding a statement immediately under the alpha_blend
          call, on the (incorrect) assumption that it would form part of the inner
          loop - and he is especially likely to make this mistake if he has, say, a
          Python background.
          >
          If the code were like this:
          >
          for(image = 0; image < numimages - 1; image++)
          {
          for(y = 0; y < height; y++)
          {
          for(x = 0; x < width; x++)
          {
          if(img[image].pixel[y][x] & ALPHA)
          {
          img[image].pixel[y][x] =
          alpha_blend(img[image].pixel[y][x],
          img[image + 1].pixel[y][x],
          img[image].alpha);
          >
          }
          }
          }
          }
          >
          that mistake would be much more difficult to make.
          >
          In my opinion, it's a good habit to get into. Obviously, some people's
          mileage varies.
          Agreed. But I would also like to add that in code like this:

          /* ... */
          }
          }
          }
          }
          }
          }

          Comments to indicate which block is being closed wouldn't hurt.

          Regards,
          Bart.

          Comment

          • Chris Dollin

            #50
            Re: for(;0;) printf(&quot;he llo&quot;);

            jmcgill wrote:
            Chris Dollin wrote:
            >jmcgill wrote:
            >>
            >>Brackets are not only proper syntax, they are also a good idea. They
            >>are anything but "clutter."
            >>
            >Opinions differ.
            >>
            >They're certainly proper syntax. Sometimes they are also necessary.
            >Appendectomi es are also sometimes necessary.
            >
            Putting braces around statements does not cause you to lose your appendix.
            Well, that's a relief.

            Urm ... and?

            --
            Chris "don't know where mine is" Dollin
            Meaning precedes definition.

            Comment

            • Richard Heathfield

              #51
              Re: for(;0;) printf(&quot;he llo&quot;);

              bart.kowalski@g mail.com said:

              <snip>
              But I would also like to add that in code like this:
              >
              /* ... */
              }
              }
              }
              }
              }
              }
              >
              Comments to indicate which block is being closed wouldn't hurt.
              Fair comment. I guess there are still a few people left who don't use vim.

              --
              Richard Heathfield
              "Usenet is a strange place" - dmr 29/7/1999

              email: rjh at above domain (but drop the www, obviously)

              Comment

              • Registered User

                #52
                Re: for(;0;) printf(&quot;he llo&quot;);


                Spidey wrote:
                for(;0;)
                printf("hello") ;
                >
                even the condition s wrong i get a hello printed on the screen
                y s this happening
                Simon Biber wrote:
                Turbo C is known to be buggy.
                Yeah, this is what happens in Turbo C 3.0, although it does warn about
                "unreachabl e code".

                Comment

                Working...