473,799 Members | 3,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

goto

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
Jul 23 '05 #1
36 6740
* Michael:

I know I know its notoriously bad! I don't want to use it. I was wondering,
does it still exist?
Yes.

If it does, I really don't understand how!?
Like always.

like what
happens if you just goto halfway through a function (no objects properly
constructed!) ,
That is forbidden by §6.6.4/3; it won't or shouldn't compile.

or a constructor itself??
?

Just intrigued!!


As you learn more you'll find many more unsafe constructs, in all languages.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2
Michael wrote:
I know I know its notoriously bad!
Long functions are bad. Short ones have no reason to use 'goto', and thus
'goto' is relatively harmless.
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??


Ordinarily, one should not learn C++ laws via "but my compiler likes it".

In this case, a little VC++ experiment is useful:

goto bar;
string foo;
bar:;

error C2362: initialization of 'foo' is skipped by 'goto bar'

The language designers took care of it. With no legacy C constructors to
support, they ordained compilers reject (relatively) non-structured 'goto'
abuses.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #3

"Alf P. Steinbach" <al***@start.no > wrote in message
news:42******** ********@news.i ndividual.net.. .
* Michael:

I know I know its notoriously bad! I don't want to use it. I was wondering, does it still exist?
Yes.

If it does, I really don't understand how!?


Like always.

like what
happens if you just goto halfway through a function (no objects properly
constructed!) ,


That is forbidden by §6.6.4/3; it won't or shouldn't compile.

so what are the limits on what you can 'goto' 'to' ?
local scope?

or a constructor itself??
?

Just intrigued!!


As you learn more you'll find many more unsafe constructs, in all

languages.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Jul 23 '05 #4
* Michael:

* Alf P. Steinbach:
* Michael:

I know I know its notoriously bad! I don't want to use it. I was
wondering, does it still exist?


Yes.

If it does, I really don't understand how!?


Like always.

like what
happens if you just goto halfway through a function (no objects properly
constructed!) ,


That is forbidden by §6.6.4/3; it won't or shouldn't compile.

so what are the limits on what you can 'goto' 'to' ?
local scope?


Quoting the standard: "It is possible to transfer into a block, but not in a
way that bypasses declarations with initialization. "

Btw., don't quote things you don't reply to or irrelevant to your reply;
snipped further quoting.

Download and install <url: http://home.in.tum.de/~jain/software/oe-quotefix/>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #5
"Michael" <sl***********@ hotmail.com> wrote in
news:d1******** **@sparta.btint ernet.com:
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!!


Yes goto still exists.

The type of goto you describe is ill-formed. See section 6.7(3) of the
Holy Standard :)
Jul 23 '05 #6
Michael wrote:
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!?

Yes it exists. Assume by "how" you mean "why". goto is extensively used
in machine-produced efficient C++ code.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7
Ioannis Vranos wrote:
Yes it exists. Assume by "how" you mean "why". goto is extensively used
in machine-produced efficient C++ code.


Please note Ioannis did not say "goto is efficient". It might be more
efficient than a well-structured function call; it might not.

Under the theory that a function takes time pushing variables onto a stack,
'goto' might generate a single branch opcode. However, that 'goto' might
live in a function that's now long enough to overflow the CPU cache. Several
small functions might have fit in the cache, making their specific function
calls faster.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #8
On Thu, 24 Mar 2005 23:53:37 +0000 (UTC), "Michael"
<sl***********@ hotmail.com> wrote:
I know I know its notoriously bad! I don't want to use it.


Why not? Goto is very useful since there is not labelled break. When
you have nested for in another for /for example/ the easiest way /and
elegant too/ to break from the external one is to use goto.

have a nice day
bye
--
Maciej "MACiAS" Pilichowski http://bantu.fm.interia.pl/

M A R G O T --> http://www.margot.cad.pl/
automatyczny t³umacz (wczesna wersja rozwojowa) angielsko-polski
Jul 23 '05 #9
Maciej Pilichowski wrote:
Michael wrote:
I know I know its notoriously bad! I don't want to use it.


Why not? Goto is very useful since there is not labelled break. When
you have nested for in another for /for example/ the easiest way /and
elegant too/ to break from the external one is to use goto.


or return.

Why is your function so long?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 23 '05 #10

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

Similar topics

30
4280
by: Hayri ERDENER | last post by:
hi, what is the equivalent of C languages' goto statement in python? best regards
51
13389
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
3260
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?
52
21983
by: Rick | last post by:
Hi, For portability, can an issue arise if we use while(1) for an infinite loop in C? If so, should we then use for(;;)? Thanks, Rick
45
2732
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. -- http://www.kashmiri-pandit.org/atrocities/index.html
77
4040
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
26649
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
2191
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
2617
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...
59
5072
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
9685
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
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10247
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...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
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
7561
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
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.