how can I jump? 
Author Message
 how can I jump?

void funA(void);
void funB(void);
void funC(void);
void funD(void);
void funE(void);
void funF(void);

int main(void)
{
 funA;

 funB;
 funC;
 funD;

 funE;
 funF;
 funA;
 funF;
 funE;

 return 0;

Quote:
}

I would like to write funF, such that once funF
is called, it will jump to funB, and execute until
funD. i.e. e.g. the main() will execute A -B-C-D
-E -B-C-D -A -B-C-D -E. In assembly, it is possible
by set push the program counter if funF is called,
pop it out at end of funD, but I dont know how to jump
in C.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

: void funA(void);
: void funB(void);
: void funC(void);
: void funD(void);
: void funE(void);
: void funF(void);

: int main(void)
: {
:  funA;

:  funB;
:  funC;
:  funD;

:  funE;
:  funF;
:  funA;
:  funF;
:  funE;

Using only the function's name as a statement has no effect. You might
as well write:
0;
1;
2;
3;
In order to execute the functions you must make the names into function
calls by adding parantheses:
funA();
funB();
funC();
funD();
and so on.

:  return 0;
: }

: I would like to write funF, such that once funF
: is called, it will jump to funB, and execute until
: funD. i.e. e.g. the main() will execute A -B-C-D
: -E -B-C-D -A -B-C-D -E. In assembly, it is possible
: by set push the program counter if funF is called,
: pop it out at end of funD, but I dont know how to jump
: in C.

C includes a goto statement, which is similar to the assembly jump
instruction, but using it between functions (ie. jump from one function
to another) is ugly in the extreme. There is of course the way of
nesting function calls. If you want funF to execute funB through funD
you can write:
void funF()
{
  funB();
  funC();
  funD();

Quote:
}

But I have no idea exactly WHY you want to do this. Could you explain
what are you trying to accomplish here?

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ |
| http://www.helsinki.fi/~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/

"To know me IS to love me."
   - JIPsoft



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

Quote:

> void funA(void);
> void funB(void);
> void funC(void);
> void funD(void);
> void funE(void);
> void funF(void);

> int main(void)
> {
>  funA;

>  funB;
>  funC;
>  funD;

>  funE;
>  funF;
>  funA;
>  funF;
>  funE;

>  return 0;
> }

As other posters have said, this won't work very well...as you are not
calling the fucntions.

Quote:

> I would like to write funF, such that once funF
> is called, it will jump to funB, and execute until
> funD. i.e. e.g. the main() will execute A -B-C-D
> -E -B-C-D -A -B-C-D -E. In assembly, it is possible
> by set push the program counter if funF is called,
> pop it out at end of funD, but I dont know how to jump
> in C.

Read the description of setjmp() and longjmp() and you will find
enlightenment :-)

Alf



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?
In the example given, FunB just indicates the begin of certain
instructions block, and FunD is the end. Between them, there is either
FunC, FunA, FunE or all of them with different kinds of combination or
sequences.

Previous example just gives one possibility. FunF just need to jump
into one label given by FunB, and jump out at FunD.

void FunB(void)
{
 //1.Begin_address,
 //2.funB execution

Quote:
};

void FunD(void)
{
 //1. FunD execution
 //End_address, How?

Quote:
}

void FunF(void)
{
 //1 save status;
 //2 set return_address, set jump_flag;
 //3 execute from Begin_address till end_address
 //4 jump back return address

Quote:
}

if main call BCECDA-F-AE-F sequentially, actually the following
sequence is followed, BCECDA-BCECD-AE-BCECDA.

I am sorry for ambiguity caused in my last message. Thanks very much.
Regards,
Linrm

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

Quote:

> void funA(void);
> void funB(void);
> void funC(void);
> void funD(void);
> void funE(void);
> void funF(void);

> int main(void)
> {
>  funA;

>  funB;
>  funC;
>  funD;

>  funE;
>  funF;
>  funA;
>  funF;
>  funE;

>  return 0;
> }

> I would like to write funF, such that once funF
> is called, it will jump to funB, and execute until
> funD. i.e. e.g. the main() will execute A -B-C-D
> -E -B-C-D -A -B-C-D -E. In assembly, it is possible
> by set push the program counter if funF is called,
> pop it out at end of funD, but I dont know how to jump
> in C.

Call them from funF:

void funF(void)
{
  funB();
  funC();
  funD();

Quote:
}

Note that you _must_ use the parens to call a function in C.

Richard



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

Quote:

> In the example given, FunB just indicates the begin of certain
> instructions block, and FunD is the end. Between them, there is either
> FunC, FunA, FunE or all of them with different kinds of combination or
> sequences.

> Previous example just gives one possibility. FunF just need to jump
> into one label given by FunB, and jump out at FunD.

> void FunB(void)
> {
>  //1.Begin_address,
>  //2.funB execution
> };

> void FunD(void)
> {
>  //1. FunD execution
>  //End_address, How?
> }

> void FunF(void)
> {
>  //1 save status;
>  //2 set return_address, set jump_flag;
>  //3 execute from Begin_address till end_address
>  //4 jump back return address
> }

> if main call BCECDA-F-AE-F sequentially, actually the following
> sequence is followed, BCECDA-BCECD-AE-BCECDA.

So F appears to do BCECD (but then why the A at the end?).
Why can't you write the following?

void FunF(void) {
    FunB();
    FunC();
    FunE();
    FunC();
    FunD();

Quote:
}

If you're avoiding function calls and the functions are just
placeholders for blocks of code in main, then you can probably
use the goto statement.  If you want to jump from a called
function back into a previously calling function (as a non-local
goto), you can use the setjmp.h header; note that it does
not allow you to continue in the function you jump out of.
There is no standard or portable way to manipulate the return
address of the function directly; you must store the address
you want to return to in a jmpbuf and use longjmp instead of
return.  Your compiler may support platform-specific extensions
that allow you to do these things or to include assembly
language instructions in your programs; if this is what you
want, you should post in another newsgroup that is specific
to your compiler and/or operating system.

--
MJSR

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

Quote:


> > I would like to write funF, such that once funF
> > is called, it will jump to funB, and execute until
> > funD. i.e. e.g. the main() will execute A -B-C-D
> > -E -B-C-D -A -B-C-D -E. In assembly, it is possible
> > by set push the program counter if funF is called,
> > pop it out at end of funD, but I dont know how to jump
> > in C.

> Read the description of setjmp() and longjmp() and you will find
> enlightenment :-)

I don't think he will. He may, eventually, succeed in doing what he set
out to do, but I suspect he'd be better off trying to learn structured
programming. Much clearer, much more enlightening <g>.

Richard



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

[snip]

Quote:
>C includes a goto statement, which is similar to the assembly
>jump instruction, but using it between functions (ie. jump from
>one function to another) is ugly in the extreme.

The goto identifier must be a label located in the current
function.  You cannot 'goto' between functions.

Richard.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 24 Aug 2002 03:00:00 GMT  
 how can I jump?

Quote:

> I don't think he will. He may, eventually, succeed in doing what he set
> out to do, but I suspect he'd be better off trying to learn structured
> programming. Much clearer, much more enlightening <g>.

I second the motion.  Please write good, structured code.  If this guy ever
manages to solve his "problem" with C, I sure don't ever want to have to
read the "solution".

--Steve



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Can you help (was Jumping then jumping back again)

2. Determining what canned preprocessor symbols are available

3. Beginner [Q] Using Canned File Open/Save dialog

4. Help with compiling a "canned" program

5. Canned Dialogs

6. F4 to jump thru find results or compiler errors (like in VS 6)

7. size of jump buffer

8. "jump in case label"

9. jump tables

10. jump table / state machine

11. Access Violation in C - Jumping into someone else's code

12. Disable MSDEV jump table

 

 
Powered by phpBB® Forum Software