calling functions

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
UR90
Posts: 29
Joined: 10 Mar 2010 19:00
Location: Slovenia

calling functions

#1 Post by UR90 » 25 Dec 2010 17:48

Hi,

i'm about writing some code and i stuck on this problem. I have a bunch of functons which i want to call them. But there is a problem.
Example: there is a main routine and before main routine i define all my routines which i want to use them. But compiler disagree with the order of how they are written. But i cannot change this order because some of routines i call them inside other routine, if you understand what's the problem. How to solve this problem.
There is a example what's the problem:

Code: Select all

 

routine2()
{
do something;
routine3();
}

routine3()
{
do something
routine1();
}

routine1()
{
do something;
routine2();
}

main()
{
do some thing;
routine1();
}
The code is just symbolic !
excuse my english

hexreader
Posts: 1786
Joined: 27 Jun 2010 12:07
Location: England

Re: calling functions

#2 Post by hexreader » 25 Dec 2010 19:32

The example code that you posted is nonsense.

You call a function that calls a function, that calls a function that....... forever!

All you will acheive is filling up the stack, however large the stack is.

If suspect that if you had a sensible program, the order of your functions would not matter.

At least.... this is my understanding. Could be wrong.
Start every day with a smile...... (get it over with) :)

UR90
Posts: 29
Joined: 10 Mar 2010 19:00
Location: Slovenia

Re: calling functions

#3 Post by UR90 » 25 Dec 2010 22:39

The code is just a symbolic like i wrote. Maybe i didn't write enough clearly. Let me try once again.
There are some function deifinitions before main funcition.
In main function is start of program which show me a menu on lcd. There are options on this menu(like: option1, option2). Let choose option1 which call a routine1 for example. In this routine i do somethings (let say that i'm incrementing counter), and also in this routine is option2 and option3. Option2 must get us back to te start of the program (the menu), instead of option3 which call another routine; routine3. In this routine, lets say i'm decrement counter and display it, whatever. In this routine3, must be also an option to get back on top (the menu) or option to go to for example to the settings,etc...
Did you understand now ?
I think that the simpliest way to program is with functions; i write what program must to do, and then just put up together.
But the problem is that, tha compiler wants to get a definiton of function which is used in one routine written before this routine. But i cannot write it like that way because then i am in "magic circle", i'll never write before and before function which is used in next routine because i call them inside them. It's complicated but i don't know how to write it otherwise.
excuse my english

UR90
Posts: 29
Joined: 10 Mar 2010 19:00
Location: Slovenia

Re: calling functions

#4 Post by UR90 » 25 Dec 2010 22:55

:roll: I solved my problem. I forgot to write prototype on the begining of the program :roll: . I'm forgotting that must be prototype and definiton of function.
My bad :mrgreen: .
excuse my english

Post Reply

Return to “mikroC PRO for AVR General”