Click here to Skip to main content
15,894,405 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how can i do this with C++ Pin
Maximilien1-May-08 10:47
Maximilien1-May-08 10:47 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 18:49
professionalRajesh R Subramanian1-May-08 18:49 
GeneralRe: how can i do this with C++ Pin
JudyL_MD2-May-08 2:12
JudyL_MD2-May-08 2:12 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 19:19
professionalRajesh R Subramanian1-May-08 19:19 
QuestionRe: how can i do this with C++ Pin
Rajkumar R1-May-08 19:28
Rajkumar R1-May-08 19:28 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 19:29
professionalRajesh R Subramanian1-May-08 19:29 
GeneralRe: how can i do this with C++ [modified] Pin
Rajkumar R1-May-08 19:24
Rajkumar R1-May-08 19:24 
GeneralRe: how can i do this with C++ Pin
Randor 2-May-08 5:36
professional Randor 2-May-08 5:36 
Rajkumar R wrote:
BTW, what's your opinion?


The goto statement has always had a bad reputation. I can remember reading many arguments in the C++ usenet newsgroups debating these issues. And beyond the argument 'The goto statement causes spaghetti code' nobody ever gave a reason why the goto statement was bad.

I'm much older now and more experienced so I can now answer this question myself now. It is my opinion that the goto statement should be avoided. The code that Judy posted is a superior method of implementing the function regardless of how ugly it is. My reasoning is quite simple in that the compiler cannot perform optimizations with all of those unconditional jumps all over the place. So by placing all of those goto statements in your function it causes the compiler to produce very different code. You can confirm this by editing your project and enabling 'Assembly With Source Code (/FAs)' for producing the ASM file.

Now I will argue a point in favor of a well placed goto statement. An experienced programmer may have intimate knowledge of compiler optimizations and determine that a goto statement will be beneficial. For example:

for(int x =0; x < iLimit;++x)
{
	for(int y =0; y < iAnotherLimit;++y)
	{
		for(int i =0;i< ilastlimit;++i))
		{
			if(FALSE == DoWork(SomeArray[x][y][i]))
			{
				goto critical_error;
			}
		}
	}
}
critical_error:
CleanUp();


In this example the compiler output will greatly benefit from the goto statement. There is no faster way to exit the nested loops. So here is my final statement regarding the issue.

Randors Conjecture:
The only time at which a C++ programmer should use a goto statement is to escape a deep nested loop.

Best Wishes,
-Randor (David Delaune)
GeneralRe: how can i do this with C++ Pin
Daniel Grunwald19-May-08 0:41
Daniel Grunwald19-May-08 0:41 
GeneralRe: how can i do this with C++ Pin
reteset2-May-08 5:14
reteset2-May-08 5:14 
QuestionHow to find tab order dynamically. Pin
Abhijit A1-May-08 0:29
Abhijit A1-May-08 0:29 
AnswerRe: How to find tab order dynamically. Pin
Rajkumar R1-May-08 1:27
Rajkumar R1-May-08 1:27 
AnswerRe: How to find tab order dynamically. Pin
Blake Miller1-May-08 12:01
Blake Miller1-May-08 12:01 
QuestionHow can I know if a 3rd party unmanaged (e.g. cpp )dll is in debug or release ? Pin
Berlus30-Apr-08 23:38
Berlus30-Apr-08 23:38 
AnswerRe: How can I know if a 3rd party unmanaged (e.g. cpp )dll is in debug or release ? Pin
Chris Meech1-May-08 4:24
Chris Meech1-May-08 4:24 
Questionneed little help Pin
Asmo'a30-Apr-08 20:13
Asmo'a30-Apr-08 20:13 
AnswerRe: need little help Pin
Christian Graus30-Apr-08 20:19
protectorChristian Graus30-Apr-08 20:19 
QuestionIEToolbar related question? Pin
ritz123430-Apr-08 19:08
ritz123430-Apr-08 19:08 
QuestionRegQueryValueExNULL,RegSetValueExString,egQueryValueExString Pin
lahom30-Apr-08 18:59
lahom30-Apr-08 18:59 
AnswerRe: RegQueryValueExNULL,RegSetValueExString,egQueryValueExString Pin
Rajkumar R30-Apr-08 20:57
Rajkumar R30-Apr-08 20:57 
QuestionRe: RegQueryValueExNULL,RegSetValueExString,egQueryValueExString Pin
David Crow1-May-08 3:00
David Crow1-May-08 3:00 
AnswerRe: RegQueryValueExNULL,RegSetValueExString,egQueryValueExString Pin
Rajkumar R1-May-08 3:42
Rajkumar R1-May-08 3:42 
AnswerRe: RegQueryValueExNULL,RegSetValueExString,egQueryValueExString Pin
Rajkumar R1-May-08 7:12
Rajkumar R1-May-08 7:12 
QuestionAnother question on "Good Practices" involving code file size... Pin
x87Bliss30-Apr-08 15:39
x87Bliss30-Apr-08 15:39 
AnswerRe: Another question on "Good Practices" involving code file size... Pin
Steve Echols30-Apr-08 18:49
Steve Echols30-Apr-08 18:49 

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.