Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Ryan Gordon's Linux Game Porting Guidance

  1. #21
    Join Date
    Jan 2011
    Posts
    1,287

    Default

    Quote Originally Posted by bison View Post
    It worked as expected. I retained the block, sans loop construct.
    In how many compilers did you test it?

  2. #22
    Join Date
    Jan 2011
    Posts
    351

    Default

    Quote Originally Posted by bison View Post
    It worked as expected. I retained the block, sans loop construct.
    AFAIK it shouldn’t compile, because you can’t write a block followed by a semicolon.

  3. #23
    Join Date
    Oct 2008
    Posts
    3,038

    Default

    Quote Originally Posted by bison View Post
    It worked as expected. I retained the block, sans loop construct.
    If you retain the block without the loop, it will work, but you have to exclude the semicolon and it looks weird. It's very hard not to screw that up eventually, because someone will come along and "fix" the missing semicolon.

    e.g.

    //works
    if (COND)
    MACRO()
    else
    bar();

    //fails because you can't declare if(COND) { ... }; else { } as valid.
    if (COND)
    MACRO();
    else
    bar();


    Anyway, as discussed, the do-while(0) loop is only needed to help ensure corner conditions are satisfied. There are lots of ways the macro will work without it. It's only necessary to prevent some rare things from ever becoming an issue, especially since when that happens it can be fairly hidden from view and hard to track down. So it's just better to be safe than sorry as a general rule of thumb.

    And there's no reason not to do it. The loop will always run exactly once, so it's trivial for compilers to optimize out any extra overhead. It's just a way to hack around a rough patch in the syntax of the language.
    Last edited by smitty3268; 01-18-2014 at 03:46 AM.

  4. #24
    Join Date
    Oct 2013
    Posts
    65

    Default

    Quote Originally Posted by stqn View Post
    AFAIK it shouldn’t compile, because you can’t write a block followed by a semicolon.

    Quote Originally Posted by smitty3268 View Post
    If you retain the block without the loop, it will work, but you have to exclude the semicolon and it looks weird. It's very hard not to screw that up eventually, because someone will come along and "fix" the missing semicolon.

    [snip]
    Yes, that's it -- the semicolon!

  5. #25
    Join Date
    Nov 2013
    Posts
    9

    Default

    Those were entertaining to read. Neat stuff about SDL 2.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •