Optimizing while(1);

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • unified@ozemail.com.au

    Optimizing while(1);

    Hi

    Looking for opinions on whether an optimizer could remove

    while(1) {};

    This is often used in embedded systems when it is desired to "commit
    suicide" by waiting for a watchdog reset.

    Thanks
    Colin
  • Nick Keighley

    #2
    Re: Optimizing while(1);

    On 25 Sep, 07:01, unif...@ozemail .com.au wrote:
    Looking for opinions on whether an optimizer could remove
    >
    while(1) {};
    >
    This is often used in embedded systems when it is desired to "commit
    suicide" by waiting for a watchdog reset.
    yes.

    --
    Nick Keighley

    Comment

    • Richard Bos

      #3
      Re: Optimizing while(1);

      Nick Keighley <nick_keighley_ nospam@hotmail. comwrote:
      On 25 Sep, 07:01, unif...@ozemail .com.au wrote:
      >
      Looking for opinions on whether an optimizer could remove

      while(1) {};

      This is often used in embedded systems when it is desired to "commit
      suicide" by waiting for a watchdog reset.
      >
      yes.
      No. Removing that line would change the semantics of the code (rather
      drastically), so that's not allowed.
      Of course, an optimiser still _could_ remove that line, just as an
      optimiser _could_ remove all printf() calls in your program. But neither
      would be a very good optimiser.

      Richard

      Comment

      • Ian Collins

        #4
        Re: Optimizing while(1);

        unified@ozemail .com.au wrote:
        Hi
        >
        Please don't multi-post on Usenet. Answered elsewhere as well as here...

        --
        Ian Collins.

        Comment

        • Andrew Poelstra

          #5
          Re: Optimizing while(1);

          On 2008-09-25, unified@ozemail .com.au <unified@ozemai l.com.auwrote:
          Hi
          >
          Looking for opinions on whether an optimizer could remove
          >
          while(1) {};
          >
          This is often used in embedded systems when it is desired to "commit
          suicide" by waiting for a watchdog reset.
          >
          Nope. Optimizers are not allowed to change the effect of code,
          and an infinite loop is certainly not a no-op.

          --
          Andrew Poelstra apoelstra@wpsof tware.net
          Only GOD may divide by zero. That is how he created black holes.
          -Veselin Jungic

          Comment

          • MisterE

            #6
            Re: Optimizing while(1);

            unified@ozemail .com.au wrote:
            Hi
            >
            Looking for opinions on whether an optimizer could remove
            >
            while(1) {};
            >
            This is often used in embedded systems when it is desired to "commit
            suicide" by waiting for a watchdog reset.
            Some compilers will appear to have removed while(1); if its the only
            thing before the end of main. This is because if you go to the full
            listing of your program you will typically find after main returns that
            compilers on embedded systems will then go into there own while(1) loop.
            Check your program output listing.

            Comment

            • Tim Rentsch

              #7
              Re: Optimizing while(1);

              Andrew Poelstra <apoelstra@supe rnova.homewrite s:
              On 2008-09-25, unified@ozemail .com.au <unified@ozemai l.com.auwrote:
              Hi

              Looking for opinions on whether an optimizer could remove

              while(1) {};

              This is often used in embedded systems when it is desired to "commit
              suicide" by waiting for a watchdog reset.
              >
              Nope. Optimizers are not allowed to change the effect of code,
              and an infinite loop is certainly not a no-op.
              The question is whether the Standard allows it; there
              are arguments both pro and con.

              Comment

              Working...