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. C / C++ / MFC
  4. do{} while (0)

do{} while (0)

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
4 Posts 3 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.
  • F Offline
    F Offline
    flyingxu
    wrote on last edited by
    #1

    I see some MFC macro use do{}while(0), for example #define AfxOutputDebugString(lpsz) \ do \ { \ USES_CONVERSION; \ _RPT0(_CRT_WARN, W2CA(lpsz)); \ } while (0) #else why use this kind of technique?

    M B 2 Replies Last reply
    0
    • F flyingxu

      I see some MFC macro use do{}while(0), for example #define AfxOutputDebugString(lpsz) \ do \ { \ USES_CONVERSION; \ _RPT0(_CRT_WARN, W2CA(lpsz)); \ } while (0) #else why use this kind of technique?

      M Offline
      M Offline
      Maxwell Chen
      wrote on last edited by
      #2

      Not anymore! Now AfxOutputDebugstring is defined as:

      #define AfxOutputDebugString TRACE

      Maxwell Chen

      1 Reply Last reply
      0
      • F flyingxu

        I see some MFC macro use do{}while(0), for example #define AfxOutputDebugString(lpsz) \ do \ { \ USES_CONVERSION; \ _RPT0(_CRT_WARN, W2CA(lpsz)); \ } while (0) #else why use this kind of technique?

        B Offline
        B Offline
        BadKarma
        wrote on last edited by
        #3

        Hi, the do{} while(0) is a technique to force the programmer to place a ; after the MACRO line so it looks more like a normal function then a macro

        codito ergo sum

        F 1 Reply Last reply
        0
        • B BadKarma

          Hi, the do{} while(0) is a technique to force the programmer to place a ; after the MACRO line so it looks more like a normal function then a macro

          codito ergo sum

          F Offline
          F Offline
          flyingxu
          wrote on last edited by
          #4

          GREAT! it makes sense.

          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