Click here to Skip to main content
15,900,816 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhy have they done this? Pin
RChin1-Jun-06 5:24
RChin1-Jun-06 5:24 
AnswerRe: Why have they done this? Pin
Viorel.1-Jun-06 5:34
Viorel.1-Jun-06 5:34 
GeneralRe: Why have they done this? Pin
RChin1-Jun-06 5:41
RChin1-Jun-06 5:41 
GeneralRe: Why have they done this? [modified] Pin
Zac Howland1-Jun-06 5:52
Zac Howland1-Jun-06 5:52 
GeneralRe: Why have they done this? [modified] Pin
RChin1-Jun-06 5:56
RChin1-Jun-06 5:56 
AnswerRe: Why have they done this? [modified] Pin
James R. Twine1-Jun-06 8:08
James R. Twine1-Jun-06 8:08 
GeneralRe: Why have they done this? [modified] Pin
Blake Miller1-Jun-06 8:18
Blake Miller1-Jun-06 8:18 
GeneralRe: Why have they done this? [modified] Pin
Zac Howland1-Jun-06 8:46
Zac Howland1-Jun-06 8:46 
James R. Twine wrote:
An excellent explaination! However, I will offer one more use of the do/while(0) block. I have seen it used as a way to provide goto-like functionality without actually using the word goto.

For example, if you needed to jump out of the middle of the block, simply executing a break will take you to the bottom of the block, simulating a goto to a label at the end of the block.

It was a bit confusing the first time I saw code that used the do/while(0) like that...


People that code like that do so for job-security. You should NEVER do that. If you actually look at the assembly code produced by the compiler when you write a do-while(0) with a break instead of just using goto, you'll notice it is exactly the same as when you do write a goto.

Although, your reasoning does offer another good reason for making this a function instead of a macro. Instead of a goto or break, you just return if you get to a state that needs such. Much cleaner, and you won't have someone asking you what the heck you are doing when they have to maintain your code.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac
AnswerRe: Why have they done this? Pin
toxcct1-Jun-06 5:46
toxcct1-Jun-06 5:46 
QuestionSDL window in MFC application. Pin
Manjunath S1-Jun-06 5:22
Manjunath S1-Jun-06 5:22 
QuestionRe: SDL window in MFC application. Pin
Hamid_RT1-Jun-06 5:51
Hamid_RT1-Jun-06 5:51 
AnswerRe: SDL window in MFC application. Pin
Cedric Moonen1-Jun-06 6:05
Cedric Moonen1-Jun-06 6:05 
GeneralRe: SDL window in MFC application. Pin
Hamid_RT1-Jun-06 6:10
Hamid_RT1-Jun-06 6:10 
GeneralRe: SDL window in MFC application. Pin
Cedric Moonen1-Jun-06 6:11
Cedric Moonen1-Jun-06 6:11 
GeneralRe: SDL window in MFC application. Pin
Hamid_RT1-Jun-06 20:02
Hamid_RT1-Jun-06 20:02 
AnswerRe: SDL window in MFC application. [modified] Pin
toxcct1-Jun-06 6:19
toxcct1-Jun-06 6:19 
GeneralRe: SDL window in MFC application. Pin
David Crow1-Jun-06 7:21
David Crow1-Jun-06 7:21 
GeneralRe: SDL window in MFC application. Pin
toxcct1-Jun-06 7:24
toxcct1-Jun-06 7:24 
GeneralRe: SDL window in MFC application. Pin
ThatsAlok1-Jun-06 19:12
ThatsAlok1-Jun-06 19:12 
QuestionCString/strcpy error Pin
kitty51-Jun-06 5:07
kitty51-Jun-06 5:07 
AnswerRe: CString/strcpy error [modified] Pin
Viorel.1-Jun-06 5:15
Viorel.1-Jun-06 5:15 
AnswerRe: CString/strcpy error Pin
Karthickg1-Jun-06 5:18
Karthickg1-Jun-06 5:18 
AnswerRe: CString/strcpy error Pin
Zac Howland1-Jun-06 5:41
Zac Howland1-Jun-06 5:41 
GeneralRe: CString/strcpy error Pin
kitty51-Jun-06 5:57
kitty51-Jun-06 5:57 
GeneralRe: CString/strcpy error Pin
Zac Howland1-Jun-06 6:06
Zac Howland1-Jun-06 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.