forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Quick question

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Thu Feb 23, 2006 1:23 am    Post subject: Quick question Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Thu Feb 23, 2006 1:53 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Energy



Joined: 26 Mar 2005
Posts: 133
Location: uk/beds/flitwick

PostPosted: Thu Feb 23, 2006 1:54 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
LuMo



Joined: 21 Aug 2005
Posts: 410
Location: Austria

PostPosted: Thu Feb 23, 2006 2:40 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Thu Feb 23, 2006 2:49 am    Post subject: Reply with quote

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
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Thu Feb 23, 2006 2:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Thu Feb 23, 2006 3:02 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 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