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

J

John Smith

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?
 
S

SM Ryan

# 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.
 
M

Mike Wahler

John Smith said:
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
 
E

Emmanuel Delahaye

SM Ryan wrote on 24/09/05 :
# 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++
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top