CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

program order

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

program order
PostPosted: Sat May 24, 2008 10:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat May 24, 2008 10:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat May 24, 2008 10:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat May 24, 2008 11:37 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat May 24, 2008 7:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat May 24, 2008 10:02 pm     Reply with quote

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







PostPosted: Sun May 25, 2008 2:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun May 25, 2008 5:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun May 25, 2008 10:03 pm     Reply with quote

Download the CCS manual.
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
Look at the section on isdigit().
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group