Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Why isn't it advised to use "go to" not" in C?

Status
Not open for further replies.

kapils1982

Member level 2
Member level 2
Joined
Dec 3, 2004
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
408
Why is the use of go to not preffered in C
 

Re: c question

Because you almost don't need it. However, there are some situation where where it can be handy. For example, two loops:
for(...)
(for(...)
{ ...
if ( fault )
goto error

}
..

error: /do something/

If you used BREAK it would only stop one loop, the deepest one.
Generally it is just overused, and I think if you want to use it do it only if necessary.
Regards,
IanP
 

Re: c question

It is not preferred because you will lose track of program flow. It gives the programmer the power to "goto" any program location as and when he likes, even invalid ones, without firing off any errors. For a small program, it is easy to keep track of program flow. But for larger applications, you will get lost in debugging work in no time.
 

Re: c question

hi
no one said that it is not availabel but you are wrong in its syntax it is written as goto .. one word not go to ..

alos .. it is not preferred to use it because it doesn't save a return address such as function calling do ..

I hope this helps you
 

Re: c question

Thanks for ur replies.

It doe not save the return address .........Does do something to the cache memory???
 

Re: c question

Because ambiguity it brings along with it's use
the flow of code becomes diffcult to understand and
it dose not care of the return address

if used carefully it is not a problem

also there are methodes where it's use can be avoided
 

Re: c question

There is nothing wrong in go to but it is mainly assembly language convention so ethically not preferred in C. Otherwise people still use go to where they need explicit control and i think sometimes it's a powerful thing under conditional jumps. Excessive use is bad because it may cause the program to wrongfully jump if there is any logical error in the decision of go to.

-Regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top