Results 1 to 2 of 2

Thread: why Qt's forever macro is for(;;) rather than while(true).

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default why Qt's forever macro is for(;;) rather than while(true).

    Hi
    The forever macro in Qt is for(; .Is there any advantage of using while(true) to for(;.
    Thanks.

  2. #2
    Join Date
    Apr 2009
    Posts
    21
    Thanked 3 Times in 2 Posts

    Default Re: why Qt's forever macro is for(;;) rather than while(true).

    It's for efficiency. Compiler may generate more assembler instructions for while(true), because there is a judgment. However, if you leave the middle parameter of for( ; ; ) empty, compiler will generate a jump instruction without any judgment.

    But, modern compiler should be capable to recognize the forever true parameter of while() and generate the same assembler instructions as for( ; ; ).

    So, use both as you like.
    Last edited by freezeblue; 13th June 2009 at 15:27.

  3. The following 2 users say thank you to freezeblue for this useful post:

    babu198649 (15th June 2009), Petroz (28th September 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.