Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > best way to do this: on error goto beginning of the main()?

Reply
Thread Tools

best way to do this: on error goto beginning of the main()?

 
 
John Smith
Guest
Posts: n/a
 
      09-24-2005
I want the program to jump to the beginning of the main() if in a
function a certain error is detected. What's the best way to
handle this?
 
Reply With Quote
 
 
 
 
SM Ryan
Guest
Posts: n/a
 
      09-24-2005
John Smith <(E-Mail Removed)> wrote:
# I want the program to jump to the beginning of the main() if in a
# function a certain error is detected. What's the best way to
# handle this?
#
#

setjmp/longjmp perhaps.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
She broke your heart and inadvertently drove men to deviant lifestyles.
 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      09-24-2005

"John Smith" <(E-Mail Removed)> wrote in message
news:e0hZe.72295$(E-Mail Removed) om...
>I want the program to jump to the beginning of the main() if in a
> function a certain error is detected. What's the best way to
> handle this?


"Best" is a subjective term. But consider:

#include <stdio.h>

int func(int arg)
{
if(arg < 0)
return 0;
else
return 1;
}

int main()
{
int i = -2;

/* 'beginning of main()' */
while(!func(i))
printf("func(): invalid argument (%d)\n", i++);

printf("func(): argument (%d) OK\n", i);
return 0;
}

-Mike





 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      09-24-2005
SM Ryan wrote on 24/09/05 :
> John Smith <(E-Mail Removed)> wrote:
> # I want the program to jump to the beginning of the main() if in a
> # function a certain error is detected. What's the best way to
> # handle this?
> #
> #
>
> setjmp/longjmp perhaps.


The OP asked for the best, not the worst...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to check that you are at the beginning (the end) of an iterable? Laurent Python 20 09-09-2011 11:30 AM
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
readdir: is there a way to reset cursor to beginning? Patrick H. Perl Misc 8 02-17-2010 06:10 PM
xemacs vhdl mode goto error Thomas Fischer VHDL 10 09-01-2006 02:35 PM
Error shown when I goto complie the application that converted from v1.1. Benny Ng ASP .Net 4 02-04-2006 04:49 PM



Advertisments