On Tue, Jul 03, 2001, Shaul Karl wrote about "Re: (main_buf = *main_buf_p) is not
syntacticly like (i = *j) ?":
> Thank you for the responses.
You're welcome. I bet you didn't expect so many correct responses. Well,
I take the credit for the first response (my response is dated a whole 55
seconds before Shachar's ;) )
> 1. I wanted to have jmp_buf* passed as a function parameter in order to avoid
> a global variable. Therefore, in the function body I had to use a local
> variable and initialize it with this pointer:
> jmp_buf local_variable = *function_paramter;
Why pass a jmp_buf* when you can pass the jmp_buf itself? Since in C arrays
are in any case passed as pointers, you don't need the extra layer of
indirection. If you're worried that jmp_buf might be some sort of compound
type that can't be passed as a parameter, worry no more: remember, setjmp()
and longjmp() are functions too, and if they can take a jmp_buf, so can you.
(anyway, ANSI C no longer has any problems with passing structures as
parameters, so you can pass any type (except void?) as a parameter).
So I suggest you just give the function a "jmp_buf" parameter, exactly like
setjmp/longjmp have, and forget about this useless copying.
BTW, even if you insist on passing a jmp_buf*, you don't need to copy it
to do dereference the pointer. You do something like
longjmp(*function_parameter);
(unless there's another pointer vs. array problem I'm not thinking of right
now - I'm too tired to think clearly right now ;))
> 2. The work I am doing is just my homework in a compilation course.
>..
> suppose you have an interactive program that has a "main loop" that
> prompts for and executes commands. Suppose the "read" command reads
> input from a file, doing some lexical analysis and parsing of the input
> while processing it. If a low-level input error is detected, it would
> be useful to be able to return immediately to the "main loop" instead
> of having to make each of the lexical analysis, parsing, and processing
> phases all have to explicitly deal with error situations initially
> detected by nested calls.
Interesting coincidence: the only time I *ever* used longjmp was in an
interpreter I wrote, and I used it in the error handler, which had to
reset the interpreter's state and continue processing the next statement.
--
Nadav Har'El | Tuesday, Jul 3 2001, 12 Tammuz 5761
[EMAIL PROTECTED] |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |If glory comes after death, I'm not in a
http://nadav.harel.org.il |hurry. (Latin proverb)
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]