Optimizing while(1);

Discussion in 'C Programming' started by unified@ozemail.com.au, Sep 25, 2008.

  1. Guest

    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
     
    , Sep 25, 2008
    #1
    1. Advertising

  2. On 2008-09-25, <> 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.
    >


    Nope. Optimizers are not allowed to change the effect of code,
    and an infinite loop is certainly not a no-op.

    --
    Andrew Poelstra
    Only GOD may divide by zero. That is how he created black holes.
    -Veselin Jungic
     
    Andrew Poelstra, Sep 25, 2008
    #2
    1. Advertising

  3. On 25 Sep, 07:01, 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
     
    Nick Keighley, Sep 25, 2008
    #3
  4. Richard Bos Guest

    Nick Keighley <> wrote:

    > On 25 Sep, 07:01, 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
     
    Richard Bos, Sep 25, 2008
    #4
  5. Ian Collins Guest

    wrote:
    > Hi
    >

    Please don't multi-post on Usenet. Answered elsewhere as well as here...

    --
    Ian Collins.
     
    Ian Collins, Sep 25, 2008
    #5
  6. MisterE Guest

    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.
     
    MisterE, Sep 26, 2008
    #6
  7. Tim Rentsch Guest

    Andrew Poelstra <> writes:

    > On 2008-09-25, <> 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.

    >
    > 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.
     
    Tim Rentsch, Oct 9, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    5
    Views:
    368
    Guest
    Jul 28, 2004
  2. Ben Fidge

    Optimizing ViewState

    Ben Fidge, Feb 17, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    458
    =?Utf-8?B?U2hhdW4=?=
    Feb 18, 2005
  3. Alejandro Penate-Diaz

    optimizing DropDownLists

    Alejandro Penate-Diaz, Apr 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    347
    Karl Seguin
    Apr 8, 2005
  4. =?Utf-8?B?RGlmZmlkZW50?=

    Question on optimizing a piece of code

    =?Utf-8?B?RGlmZmlkZW50?=, Jun 9, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    412
    Patrice
    Jun 9, 2005
  5. Vaclav

    optimizing meta tags

    Vaclav, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    348
    Vaclav
    Jun 12, 2005
Loading...

Share This Page