Connecting Tech Pros Worldwide Forums | Help | Site Map

Functions problem

itportal
Guest
 
Posts: n/a
#1: Dec 30 '05
Hello,

I've got the following problem. FuncB uses recursion and calls itself.
Sometimes FuncB calls FuncA, but then FuncA should call FuncB ... which
actually returns an error..

void FuncA(){
FuncB();
}

void FuncB(){
FuncB();
FuncA();
}

Ani ideas how to make that thing work ...


marcwentink@hotmail.com
Guest
 
Posts: n/a
#2: Dec 30 '05

re: Functions problem


> ... which actually returns an error..

What error? If your call stacks goes out of limit, probably you should
write something like

void FuncA(){
if ( "not enough yet")
FuncB();
}


void FuncB(){
FuncB();
if ( "not enough yet")
FuncA();
}

somehow the recursion must stop at some time

itportal
Guest
 
Posts: n/a
#3: Dec 30 '05

re: Functions problem


The recursion has an end, but I get:
"conflicting types for 'FuncB' "

itportal
Guest
 
Posts: n/a
#4: Dec 30 '05

re: Functions problem


plus:
"previous implicit declaration of 'FuncB' was here"

marcwentink@hotmail.com
Guest
 
Posts: n/a
#5: Dec 30 '05

re: Functions problem


itprotal:
[color=blue]
> The recursion has an end, but I get:
> "conflicting types for 'FuncB' "[/color]

It's still a bit unclear what the exact error is, is the compiler
complaining about the return type of function FuncB? Could you post the
whole and complete message, and even some code, may-be?

Luke Meyers
Guest
 
Posts: n/a
#6: Dec 30 '05

re: Functions problem


Did you declare FuncB before using it in FuncA? It sounds as though
perhaps you didn't.

If that's not it, then I suggest that you should post the actual code
which causes this problem, because nothing in the snippet you posted is
missing whatever it is that's causing your code not to work.

Luke

marcwentink@hotmail.com
Guest
 
Posts: n/a
#7: Dec 30 '05

re: Functions problem


> "previous implicit declaration of 'FuncB' was here"

Could you possibly have mistaken a statement that calls FuncB, and a
statement that defines FuncB

Like:

// defines the function, make the following code aware there is such a
function, but does not call it
void FuncB(int j, int k);


// calls the function
FuncB(j,k);

the difference is the types you declare in a definition, "void" as
return, and two "ints" for the parameters in this example.

Marc

itportal
Guest
 
Posts: n/a
#8: Dec 30 '05

re: Functions problem


The code is very long an complicated.

I have probably made wrong declarations. I declared the functions and
now I get the error:
[Linker error] undefined reference to `FuncA'

itportal
Guest
 
Posts: n/a
#9: Dec 30 '05

re: Functions problem


Oppps ... I've mistaken the name of the funcs.

Now everything is OK.

The problem had been that I haven't decalred the funcs. So long code
that I get lost in it ;)

10x

Closed Thread