Free Republic
Browse · Search
General/Chat
Topics · Post Article

To: so_real

Magic numbers aside, I’m confused about how adding a “goto” to C++ code is an “improvement.”


7 posted on 11/12/2015 7:06:12 AM PST by Steely Tom (Vote GOP: A Slower Handbasket)
[ Post Reply | Private Reply | To 5 | View Replies ]


To: Steely Tom
There's nothing wrong with goto if it is coded properly.

Using it just to create spaghetti is not coding properly. Using it to exit is, IMHO.

9 posted on 11/12/2015 7:13:06 AM PST by ShadowAce (Linux - The Ultimate Windows Service Pack)
[ Post Reply | Private Reply | To 7 | View Replies ]

To: Steely Tom

I'm not a big fan of "goto" statements either. But they do serve a purpose, and I'll give them a pass when used to fill the "abort on failure" situation. That being said, "do {} while(0);" with an error code set and a "break" on failure is, IMHO, more structured and readable than a "goto". I call it my "breakable IF statement".


25 posted on 11/12/2015 9:27:51 AM PST by so_real ( "The Congress of the United States recommends and approves the Holy Bible for use in all schools.")
[ Post Reply | Private Reply | To 7 | View Replies ]

To: Steely Tom; ShadowAce
...adding a "goto" to C++ code ...

Actually, the code is 'C', not 'C++' (quoting from the referenced email, the file name is "net/ipv6/ip6_output.c".

That being said, getting gracefully out of a deep dive into a multidimensional 'for' loop is sometimes best achieved with a 'goto'. Seldom, but occasionally. ;)
31 posted on 11/12/2015 2:41:30 PM PST by Montana_Sam (Truth lives.)
[ Post Reply | Private Reply | To 7 | View Replies ]

Free Republic
Browse · Search
General/Chat
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson