View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
program order |
Posted: Sat May 24, 2008 10:09 am |
|
|
Hi
I have a program where I have many functions and one of them depend other and when compile my program it give an error for example...
void funct1()
{
if (S1==0) funct2();
}
void funct2()
{
if (S2==0) funct1();
}
now have an error on funct2() "undefined identifier -- funct2" and if I change order of functions give me same error but on funct1().
dont is possivel define this 2 functions in other way?
regards |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sat May 24, 2008 10:26 am |
|
|
simply because the compiler doesnt know "funct2()" when compiling funct1().
you have to use function prototype, place this before the first function:
void funct2();
after that, the compiler will be aware what the second function is expected to be. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sat May 24, 2008 10:58 am |
|
|
Hi
it not work.... I make that:
Code: | void funct2()
{
if (S2==0) funct1();
}
void funct1()
{
if (S1==0) funct2();
} |
and try that:
Code: | void funct2();
void funct1()
{
if (S1==0) funct2();
}
void funct2()
{
if (S2==0) funct1();
} |
dont is possible define functions at begin of program?
regards |
|
|
meereck
Joined: 09 Nov 2006 Posts: 173
|
|
Posted: Sat May 24, 2008 11:37 am |
|
|
filjoa wrote: | Hi
it not work.... I make that:
void funct2()
{
if (S2==0) funct1();
}
void funct1()
{
if (S1==0) funct2();
}
and try that:
void funct2();
void funct1()
{
if (S1==0) funct2();
}
void funct2()
{
if (S2==0) funct1();
}
dont is possible define functions at begin of program?
regards |
What is the error message shown? |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sat May 24, 2008 7:15 pm |
|
|
in the 1st example: "undefined identifier -- funct2"
in the 2nd example: recursion not permitted [funct2] but stop error at the end on "}" of main function...
some ideas ?
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 24, 2008 10:02 pm |
|
|
Quote: | in the 2nd example: recursion not permitted |
Please see page 1 of the CCS manual (page 13 in the Acrobat reader):
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
It says:
Quote: |
When compared to a more traditional C compiler, PCB, PCM,
and PCH have some limitations. As an example of the limitations,
function recursion is not allowed. |
|
|
|
Ttelmah Guest
|
|
Posted: Sun May 25, 2008 2:49 am |
|
|
The way to deal with this, is to use a master dispatcher. So (for instance)
Code: |
enum func_required {exit,func1,func2};
void funct1(void) {
if (S1==0) {
func_required=func2;
return;
}
}
void funct2(void) {
if (S2==0) {
func_required=func1;
return;
}
}
void dispatcher(void) {
int1 loop=true;
while (loop) {
switch (func_required) {
case exit :
loop=false;
break;
case func1 :
funct1();
break;
case func2 :
funct2();
break;
}
}
}
//Then in the 'main'
func_required=func1;
dispatcher();
|
So what happens, is that the functions are all _individually_ called from inside the dispatcher, which decides what one to call, based on the 'func_required' value. When a function, wants to return right back to the 'main' code, it sets this variable to 'exit'. The individual functions, will keep being called so long as 'func_required' is set to their value. When you want to change to another routine, change the func_required value, and return. the dispatcher will then select the requested routine.
Hopefully you get the idea.
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sun May 25, 2008 5:23 pm |
|
|
Hi
I don't understand much last suggestion but modify some lines and make the same...
but I have other questions...
have other way for write that?
Quote: | if ((string[15]!="0") || (string[15]!="1") || (string[15]!="2") || (string[15]!="3") || (string[15]!="4") || (string[15]!="5") || (string[15]!="6") || (string[15]!="7") || (string[15]!="8") || (string[15]!="9")) |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|