Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. while(0) ?

while(0) ?

Scheduled Pinned Locked Moved Managed C++/CLI
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CiNN
    wrote on last edited by
    #1

    #define R(l,r,i) do { l ^= p[i]; r ^= F(l); } while(0) why a while(0) ? :doh:

    T M 2 Replies Last reply
    0
    • C CiNN

      #define R(l,r,i) do { l ^= p[i]; r ^= F(l); } while(0) why a while(0) ? :doh:

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      useless so... but avoid using such a macro in your code...


      TOXCCT >>> GEII power
      [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

      1 Reply Last reply
      0
      • C CiNN

        #define R(l,r,i) do { l ^= p[i]; r ^= F(l); } while(0) why a while(0) ? :doh:

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        The do/while is there to provide a block. Without the do/while, this code:

        if (somefunc())
        R(a,b,c);

        wouldn't give the right behavior because only the first statement would be inside the if block. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        T 1 Reply Last reply
        0
        • M Michael Dunn

          The do/while is there to provide a block. Without the do/while, this code:

          if (somefunc())
          R(a,b,c);

          wouldn't give the right behavior because only the first statement would be inside the if block. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          but it could have provided these instructions into a block ( { } ) without do/while...

          #define R(l,r,i) { l ^= p[i]; r ^= F(l); }


          TOXCCT >>> GEII power
          [toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 4:49 Wednesday 8th February, 2006

          S 1 Reply Last reply
          0
          • T toxcct

            but it could have provided these instructions into a block ( { } ) without do/while...

            #define R(l,r,i) { l ^= p[i]; r ^= F(l); }


            TOXCCT >>> GEII power
            [toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 4:49 Wednesday 8th February, 2006

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            Not in all cases. Here's two versions of a macro: #define FOO1(n) { return n; } #define FOO2(n) do { return n; } while(0) Now given these two macros this will not complile:

            if ( 1 )
              FOO1(1);
            else
              return 0;
            

            But this will:

            if ( 1 )
              FOO2(1);
            else
              return 0;
            

            So there is method to the madness. Steve

            T 1 Reply Last reply
            0
            • S Stephen Hewitt

              Not in all cases. Here's two versions of a macro: #define FOO1(n) { return n; } #define FOO2(n) do { return n; } while(0) Now given these two macros this will not complile:

              if ( 1 )
                FOO1(1);
              else
                return 0;
              

              But this will:

              if ( 1 )
                FOO2(1);
              else
                return 0;
              

              So there is method to the madness. Steve

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              :-O oh, my mistake... yeah, the problem comes from the **;** following the expansion of the macro... a ; cannot come just after a } (except in a user-defined type definition - class, struct, enum, union...)


              TOXCCT >>> GEII power
              [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups