CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Jump to defined place in the code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
blups



Joined: 05 May 2011
Posts: 10

View user's profile Send private message

Jump to defined place in the code
PostPosted: Thu Jul 18, 2013 7:13 am     Reply with quote

Hi peeps,

I need to do some kind of system reset in some special case. The system reset is but not the MCU one. So i have to jump in a defined place in the code. Something like goto statement. My project contains many .h files and to work with goto i have to be in same file with the label. In other words I have a situation, where my lable and goto statements are in a different files. The compiler crashes.
Do you know some tricky way to do this?
Much 10x in advance...

GR
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Jul 18, 2013 8:01 am     Reply with quote

A jump 'between routines', will leave the stack imbalanced, and eventually crash the code.

Easiest is to use 'reset_cpu', and then test 'restart_cause', to detect that this is a software restart, and not a hardware one.

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Jul 18, 2013 8:28 am     Reply with quote

OR....
setup a function - called 'init()'
with a flag that is defined one way on cpu_reset

asin
int dowhat=0; in you prefix code area before main

and another value in active code that will call it as you desire later
for your warm boot


then call it at the start of main()

BTDTGTTS
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 5:57 am     Reply with quote

C has a perfectly functional goto command. It is rarely used but there are times when it is the right tool for the job.
_________________
The search for better is endless. Instead simply find very good and get the job done.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 7:20 am     Reply with quote

SherpaDoug wrote:
C has a perfectly functional goto command. It is rarely used but there are times when it is the right tool for the job.


Which is NEVER. See Ttelmah's comments above.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Jul 22, 2013 8:14 am     Reply with quote

In C goto has function scope: you can only jump to somewhere within the same function. The reason is presumably to avoid the stack corruption that out of function jumps necessarily imply.

While I am firmly in the "dont use gotos" camp, there are times when its possibly useful. Jumping out of a highly nested command handler on some error condition for example.

To jump out of one routine into another in a totally different source file is NOT a good idea. Indeed, it shows there's something badly wrong with the program's architechure and structure. If you really need to do some kind of "reset" or "warm start" then to a proper restart and detect that in your initialisation code. Most of the time, that's not needed, and there's a much simpler way to acheive the same effect.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group