473,729 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why are GOTO's not used ...

why are GOTO's not used they just a simple JMP instructions what's bad
about them
Aug 17 '08 #1
59 5047

"raashid bhatt" <ra**********@g mail.comwrote in message news:
why are GOTO's not used they just a simple JMP instructions what's bad
about them
Indeed. C has a perfectly functional goto statement, which will compile to a
basic assembler jump.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Aug 17 '08 #2
raashid bhatt said:
why are GOTO's not used they just a simple JMP instructions what's bad
about them
goto Try

refuse to use them at all. Then wait six months. Then go and make some
goto medium-scale

Then wait six months. Then go and make some medium-scale changes to the
goto code

medium-scale changes to the code (not cosmetic, but not drastic surgery
goto either

Now try without them. Specifically, write a large program in which you
goto refuse

code (not cosmetic, but not drastic surgery either). Consider how difficult
goto this

either). Consider how easy this is, relative to the other program.
goto end

this is.
goto Now

Try them. Specifically, write a large program in which you use them freely.
goto Then

end

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 17 '08 #3
Malcolm McLean wrote:
>
"raashid bhatt" <ra**********@g mail.comwrote in message news:
>why are GOTO's not used they just a simple JMP instructions what's
bad about them
Indeed. C has a perfectly functional goto statement, which will
compile to a basic assembler jump.
I note that you have failed to actually answer the OP's question.

To the OP:

It's not true to say that the goto is "not used". It's use is often
discouraged, but it's nevertheless used in some situations. Unlike
gets, goto *can* be used wisely, though in my experience, you need
quite some practise in programming before you can acquire this ability.
In short, goto is prone to abuse by beginners (though that's not to say
that *all* beginners abuse goto or that experienced programmers never
do so).

It's overuse tends to break up the "higher level" structure of the code
and it's flow of control making it hard to read and hard to extend. It
also throws away the intent the programmer had in coding a particular
construct which high-level statements can preserve and convey.

Just compare these two code fragments that do the same thing:

1.

for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
putc('*', stdout);
}
putc('\n', stdout);
}

2.

i = 0;
outer_loop:
if (i == 10) {
goto end_loop;
}
else {
i++;
}
j = 0;
inner_loop:
putc('*', stdout);
if (j == 10) {
putc('\n', stdout);
goto outer_loop;
}
else {
j++;
goto inner_loop;
}
end_loop:
/* proceed */

You might as well program in assembler.

Aug 17 '08 #4

"santosh" <sa*********@gm ail.comwrote in message
>
You might as well program in assembler.
That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work. Then
slowly replace the C control structures with ifs on a single variable, eg
if(flag) and gotos, to make it more and more assembly-like. Eventually each
line of C becomes one line of assembler. Then you can code up the assembly
function.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Aug 17 '08 #5
Malcolm McLean wrote:
>
"santosh" <sa*********@gm ail.comwrote in message
>>
You might as well program in assembler.
That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work. Then
slowly replace the C control structures with ifs on a single variable,
eg if(flag) and gotos, to make it more and more assembly-like.
Eventually each line of C becomes one line of assembler. Then you can
code up the assembly function.
Um, is there any *purpose* to such an exercise?

Aug 17 '08 #6
On 2008-08-17, santosh <sa*********@gm ail.comwrote:
Malcolm McLean wrote:
>>
"santosh" <sa*********@gm ail.comwrote in message
>>>
You might as well program in assembler.
That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work. Then
slowly replace the C control structures with ifs on a single variable,
eg if(flag) and gotos, to make it more and more assembly-like.
Eventually each line of C becomes one line of assembler. Then you can
code up the assembly function.

Um, is there any *purpose* to such an exercise?
I think the "purpose" is to write an assembler program without confusing
the hell out of yourself.

--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Aug 17 '08 #7
Andrew Poelstra wrote:
On 2008-08-17, santosh <sa*********@gm ail.comwrote:
>Malcolm McLean wrote:
>>>
"santosh" <sa*********@gm ail.comwrote in message

You might as well program in assembler.

That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work.
Then slowly replace the C control structures with ifs on a single
variable, eg if(flag) and gotos, to make it more and more
assembly-like. Eventually each line of C becomes one line of
assembler. Then you can code up the assembly function.

Um, is there any *purpose* to such an exercise?

I think the "purpose" is to write an assembler program without
confusing the hell out of yourself.
The method Malcolm explains *will* confuse me. Why try to imitate the
translation process of the C compiler while you can cut to the chase
and write in assembler to begin with?

Aug 17 '08 #8
On 2008-08-17, santosh <sa*********@gm ail.comwrote:
Andrew Poelstra wrote:
>On 2008-08-17, santosh <sa*********@gm ail.comwrote:
>>Malcolm McLean wrote:
"santosh" <sa*********@gm ail.comwrote in message
>
You might as well program in assembler.
>
That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work.
Then slowly replace the C control structures with ifs on a single
variable, eg if(flag) and gotos, to make it more and more
assembly-like. Eventually each line of C becomes one line of
assembler. Then you can code up the assembly function.

Um, is there any *purpose* to such an exercise?

I think the "purpose" is to write an assembler program without
confusing the hell out of yourself.

The method Malcolm explains *will* confuse me. Why try to imitate the
translation process of the C compiler while you can cut to the chase
and write in assembler to begin with?
C is much easier to structure - writing from assembler from the start
would obscure the business logic, making it much harder to complete.

--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Aug 17 '08 #9
"Malcolm McLean" <re*******@btin ternet.comwrite s:
"santosh" <sa*********@gm ail.comwrote in message
>>
You might as well program in assembler.
That's actually quite a good technique.

Write the function in C, with the emphasis on getting it to work.
And now you're done.
Then
slowly replace the C control structures with ifs on a single variable,
eg if(flag) and gotos, to make it more and more
assembly-like. Eventually each line of C becomes one line of
assembler. Then you can code up the assembly function.
Then measure the relative performance of your original C code
(compiled with maximum optimization) vs. the performance of the
assembly code. It's not unlikely that you'll find you've wasted your
time -- especially when you have to go through the whole exercise
again if you need the program to work on a different platform.

Your method might be a good one *if* you've confirmed (by
measurement!) that a particular chunk of code is a performance
bottleneck, that you can't correct the performance problem without
resorting to assembly language, and that it's worth the cost of the
extra effort and loss of portability.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 17 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
6735
by: Michael | last post by:
Hi, I know I know its notoriously bad! I don't want to use it. I was wondering, does it still exist? If it does, I really don't understand how!? like what happens if you just goto halfway through a function (no objects properly constructed!) , or a constructor itself?? Just intrigued!! Mike
51
13377
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this wrong????? Function x select case z
37
3252
by: Tim Marshall | last post by:
From http://www.mvps.org/access/tencommandments.htm 9th item: Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you from the path of righteousness. What about also using it as a means of exiting a procedure?
17
2314
by: Mike Hofer | last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my principal language has been BASIC, QBASIC, then Visual Basic, and finally Visual Basic .NET. But lately, I've been using C# and I absolutely *love* it. It makes me think more about what I'm doing it before I just spew code into the editor. I'm writing better code than ever. The only thing so far that I don't like about it is the switch construct. I can't do this:
77
4016
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that goto sometimes makes program some more cleaner and easy to understand and also quite useful (in error handling cases). So why goto is outlawed from civilized c programmers community. is there any technical inefficiency in that.
34
26644
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
3
2189
by: electrician | last post by:
Yes, no GOTO. This is a major blunder on part of the creators of these tools. GOTO gives the programmer the absolute control over the program. Yes, no matter what, a GOTO sends the program to where YOU want and takes the power away from the mean spirited CREATORS. Yes, even GOD gave us free will! But the creators of JavaScript have decided they will forever interfere in how YOU program. THEY have decided to keep GOTO to themselves...
17
2609
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code which shows harmfullness of GOTO. SoftEast...
7
288
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
8931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8767
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9293
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9221
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8165
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.