Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 2 months ago.
Multiple Functions
Hello all,
I am writing a large program and want to break it down in to multiple functions for easier reading and trouble shooting. the problem i am running into is the functions need to interact with each other. But if one function is above the other function the upper function cannot see the lower function. What is the proper way to address this issue? I have included a example code that causes the same error, and the error.
Thank you!
Error: Identifier "FunctionTwo" is undefined in "main.cpp", Line: 21, Col: 10
void FunctionOne() { FunctionTwo(); } void FunctionTwo() { while (1) { } }
1 Answer
8 years, 2 months ago.
You will need to use a Function prototype which are common to the C language. Using this method, your error will be resolved.
https://en.wikipedia.org/wiki/Function_prototype
so apply before FunctionOne():
void FunctionTwo();
Perfect! That work great is there any adverse effect if i call out several functions as prototype?
Also when i am calling out prototype it needs to include the same variable for the function correct?
posted by 20 Sep 2016Hi Tyler. Excellent. No issues to list as many prototypes as required. During my days at the university, our prof demanded this style to alert the reader that these functions will follow somewhere in the code list. Makes perfect sense. The only warnings are of course common sense ones such as when you declare your prototype to be different than the actual routines which follow - this will raise the respective error. The prototypes will dominate the definition of what is to follow. Prototypes just make for better code reading. Have fun coding !
posted by 20 Sep 2016