| View previous topic :: View next topic |
| Author |
Message |
Energy
Joined: 26 Mar 2005 Posts: 133 Location: uk/beds/flitwick
|
Posted: Thu Feb 23, 2006 1:23 am Post subject: Quick question |
|
|
when I try to call a function I get this error...
implicit declaration of function menu
| Code: |
int main()
{
pspDebugScreenInit();
SetupCallbacks();
int choice;
choice = menu();
sceKernelSleepThread();
return 0;
}
int menu(void)
{
// ...
return 0;
}
|
What am I being thick over?
Energy |
|
| Back to top |
|
 |
Dr. Vegetable
Joined: 14 Nov 2005 Posts: 171 Location: Boston, Massachusetts
|
Posted: Thu Feb 23, 2006 1:53 am Post subject: |
|
|
You are calling menu() before/above the point where you define it. You either need to have a function prototype at the top of the file or else move the definition of menu() above your main() function.
| Code: |
int menu(void); // <-- function prototype, tells the compiler how to call menu()
int main()
{
pspDebugScreenInit();
SetupCallbacks();
int choice;
choice = menu();
sceKernelSleepThread();
return 0;
}
int menu(void)
{
// ...
return 0;
} |
The "implicit declaration" warning means that you have called a function without first defining its calling convention, so the C compiler has implicitly assumed that it knows how to call the function. In your case, you get lucky because the assumption is that the function takes no parameters (void) and returns an integer. In C++, implicit declarations are not allowed.
Last edited by Dr. Vegetable on Thu Feb 23, 2006 1:57 am; edited 1 time in total |
|
| Back to top |
|
 |
Energy
Joined: 26 Mar 2005 Posts: 133 Location: uk/beds/flitwick
|
Posted: Thu Feb 23, 2006 1:54 am Post subject: |
|
|
| Dr. Vegetable wrote: | You are calling menu() before/above the point where you define it. You either need to have a function prototype at the top of the file or else move the definition of menu() above your main() function.
| Code: |
int menu(void); // <-- function prototype, tells the compiler how to call menu()
int main()
{
pspDebugScreenInit();
SetupCallbacks();
int choice;
choice = menu();
sceKernelSleepThread();
return 0;
}
int menu(void)
{
// ...
return 0;
} |
|
thanks... I knew it was something stupid lol |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Thu Feb 23, 2006 2:40 am Post subject: |
|
|
alternative you could just move the function menue above the function main... _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Thu Feb 23, 2006 2:49 am Post subject: |
|
|
move function int menu() above int main()
using function prototypes is not really common
nowadays ... its old K&R style but any modern
compiler should still compile your program
just fine ... and there is no need for prototypes
anymore ...unless you really is your style to
have functions on after main _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Thu Feb 23, 2006 2:50 am Post subject: |
|
|
move function int menu() above int main()
using function prototypes is not really common
nowadays ... its old K&R style but any modern
compiler should still compile your program
just fine ... and there is no need for prototypes
anymore ...unless you really is your style to
have functions on after main _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
Dr. Vegetable
Joined: 14 Nov 2005 Posts: 171 Location: Boston, Massachusetts
|
Posted: Thu Feb 23, 2006 3:02 am Post subject: |
|
|
You may notice that I suggested both approaches. Which coding style to use is largely a matter of personal preference, but in a larger project it can be very difficult (and counter-intuitive) to try to order all of your functions top-down so that no prototypes are ever needed. If you always define a prototype for every function, you never need to worry about this.
My personal preference is to avoid prototypes during development of static local functions, and to always use them for any global functions. But once the design of my local functions has stabilized, I usually extract prototypes to the top of the file anyway. I find this practice makes it easier to harvest the code for re-use in other projects, because you can scan a list of function prototypes more easily than you can scan an entire source file to see what functionality is available for the borrowing.
Sometimes there's a good reason to go Old School. |
|
| Back to top |
|
 |
|