warnning main is normally a non-static function cant comply?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

warnning main is normally a non-static function cant comply?

Post by sg57 »

thats what i get whyen trying to comply,

warning: 160: main is normally a non-statick function

warning: 167: control reaches end of non-void function

i fixed up my game and put a repeat in it by making everything that was in the main, one big function, now i call the function in the loop but it gives me those 2 errors, heres my code (main())

Code: Select all

int main() {
	restart();
	sceKernelSleepThread();
	return 0;
}
}
}
}
i have to have all those '}' or else i get a syntax error, and because i ahve several loops in the function
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

Although you didn't post enough code for anyone to be sure, it sounds like you have the closing brackets '}' for the loops in your main() routine, and the open brackets '{' for the loops inside of your restart() function. You cannot do this. You must end the loops inside the function, so move the extra brackets there.

I'm guessing your code looks something like this:

Code: Select all

void restart()
{
   while (dontEndTheGame)
   {
      // Play the game...
}

int main()
{
   } /* end while loop */
}
When you moved the loop into the function, you should copy the brackets:

Code: Select all

void restart()
{
   while (dontEndTheGame)
   {
      // Play the game...
   } /* end while loop */
}

int main()
{
}
If you still have problems, you should post the code for your whole program to get better advice. Hope this helps!
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

thanks it helps, im gonna og to test it now, all i had before was 3 loops, one for hte start menu kind of thing, 1 in the middle for playing the game, and one at the end displaying either end game game over , etc. but ya if it still doesnt work ill put all my code seeing as how my game is already a beta nd its up on intenet
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

ok i cant get it, whats the difference between int and void?

i took donw my code because i think ig ot it and its a waste of space wiht a huge thing of code right h=there soi ill repost it if i have any problems
Last edited by sg57 on Mon Jan 23, 2006 8:48 am, edited 2 times in total.
User avatar
ReKleSS
Posts: 73
Joined: Sat Jun 18, 2005 12:57 pm
Location: Melbourne, Australia

Post by ReKleSS »

Get an editor with auto indenting or something - or use indent. For some reason your main function is inside the repeat() function (which should have been obvious from all the }'s down the bottom)... I'm guessing you were seeing errors about unclosed brackets, and just stuck them down the bottom.

By the looks of it, those two extra }'s from the bottom should go just above main().

Int and void? int is an integer value, void is nothing. The proper definition of main is

Code: Select all

int main(int argc, char *argv);
but just int main() or void main() should be fine.
-ReK
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

Dr. Vegetable wrote:Although you didn't post enough code for anyone to be sure, it sounds like you have the closing brackets '}' for the loops in your main() routine, and the open brackets '{' for the loops inside of your restart() function. You cannot do this. You must end the loops inside the function, so move the extra brackets there.

I'm guessing your code looks something like this:

Code: Select all

void restart()
{
   while (dontEndTheGame)
   {
      // Play the game...
}


wait, so are you saying that ithere should only be 1 { at the end of the main() { ? if so im gonna go and move the { } around see what i can do....

int main()
{
   } /* end while loop */
}
When you moved the loop into the function, you should copy the brackets:

Code: Select all

void restart()
{
   while (dontEndTheGame)
   {
      // Play the game...
   } /* end while loop */
}

int main()
{
}
If you still have problems, you should post the code for your whole program to get better advice. Hope this helps!
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

WAIT WAIT WAIT, it hink ig ot it, i moved all the '}'s from the end into the end of the function now i get a hole new error....ill fix it tho!
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

ya i got it, but i think ur post was delayed or something cause i fixed it then posted about it but i didnt se urs there...weird, o well i did get it fixed, i just had to move all those closing brackets into the functions end and then fix a few more errors but i got it working, now i just need to get some sceDisplayScreenWaitVblankStart's and flipScreen();s in there to get the images to show
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Just to clarify a few things that may not be clear.

The "int main()" or "void main()" and the return value are linked.

so if you use "int main()", at the end of the main function you need to return an integer - return 0;

Code: Select all

int main() {
   funct_1();
   return 0;
}
or if you use "void main()", at the end of the main function you need to return an integer - return 0;

Code: Select all

void main() {
   funct_1();
}
see how void doesnt have a return value... also this doesnt comply with C standards, and you shouldnt do it.

The return value can be used to say if the program exited correctly. This is commonly used as 0, and if you had a check in the program somewhere that had to exit the program you could use return 1.

Code: Select all

int main() {

   if (someValidCheck() == false) {
   return 1;
   }
   else {
   // rest of the program
   other_functs();
   }

   return 0;

} // end main
also, if it helps, use comments to show yourself where the closing brackets go. It helps for programs with lots of loops:
code with 3 seperate loops executed after each other

Code: Select all

int main() {

for &#40;i = 1; i <= 10; i++&#41; &#123;
  ...code...
&#125; // end i loop

for &#40;j = 1; j <= 10; j++&#41; &#123;
  ...code...
&#125; // end j loop

for &#40;k = 1; k <= 10; k++&#41; &#123;
  ...code...
&#125; // end k loop

&#125; // end main
code with 3 NESTED loops executed at the same time...

Code: Select all

int main&#40;&#41; &#123;

for &#40;i = 1; i <= 10; i++&#41; &#123;
  ...code...

    for &#40;j = 1; j <= 10; j++&#41; &#123;
      ...code...

        for &#40;k = 1; k <= 10; k++&#41; &#123;
       ...code...

       &#125; // end k loop
   &#125; // end j loop
&#125; // end i loop

&#125; // end main


BTW, the code isnt exactly right, just intended to show the things Ive mentioned. Hope it helps. (in a hurry so couldnr explain it as well as I'd have liked!!)

HaQue
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

n problkem that helps alot, but i have one question that in lua is a couple numbers in side of an arguemnet and its doen, but hwo do make text/pictures display for a certain amount of time?

everytime i put a number in side the sceDisplayScreenWaitVblankStart('here'), i get:

Code: Select all

main.c&#58;197&#58; error&#58; too many arguments to function 'sceDisplayWaitVblankStart'
in LUA you just plop a number in ther and walaa

but apparently its different in c/c++?

anyway, im also having touble with calling functions in the main program,

like this here:

Code: Select all

SceCtrlData pad;
    sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
    if&#40;pad.Buttons & PSP_CTRL_SQUARE&#41; &#123;
                   int scroll&#40;&#41;;
&#125;   else if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;
                   void repeat&#40;&#41;;                    
&#125;
maybe it has to do with the return 0s?i dont have any yet i see peoples with them so i guess ill try it out but help if u can please
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

o and the things inside the if staements are functions i defined at the top of the list, i think i have to put 'return 0;' after that line but i dont know why, probably because its 'true' that i want to run that fucntion if i press square/cross? i dunno please help
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Hi,
This is not a nasty toned message, just some freindly advice...

I think you should look at some simple programming examples. none of what you are asking is really PSP specific, and you cant expect people to write your code for you.

If you spend some time grasping these basic things, your coding will be alot easier and more fullfilling than just fixing things so they work.

now:

You dont need a return() in if statements, you need 1 "return ?" statement in each function that has been coded to need one:

if you have int main() {} then you need to return an integer value at the end of the function .... "return 0;". (does NOT have to be "0"... can be whatever you need it to be!

if you have int GetSizeOfWhatever() {} then you need to return an integer value at the end of the function .... "return(size);".

if your function has the possibility of ending BEFORE you get to the end and it will miss the retrn(); at the end, you should put a return; statement at the point it will get out of that function.

hope that helps. :)

Code: Select all

int main &#40;&#41; &#123;

var = getSizeOfSomething&#40;&#41;;

printToScreen&#40;"var =" + var&#41;;

return&#40;0&#41;;

&#125; // end main

// the getSizeOfSomething function
int getSizeOfSomething&#40;&#41; &#123;
int size = 25;
return&#40;size&#41;;
&#125; // end getSizeOfSomething
dodgy I know, but instruction code is :)
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

ya i understand that, ill just look around but its hard to find something simple (besides my own) that includes analog functioning and a sceDisplayScreenWaitVblankStart with arguments to answer my question
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

Hi,
post the code containing "sceDisplayScreenWaitVblankStart('here')", it would be easier to help on that part of it.

how are you putting the int in there? I havent looked but what does that function need.

Code: Select all

are you doing sceDisplayScreenWaitVblankStart&#40;'23'&#41;
or

Code: Select all

sceDisplayScreenWaitVblankStart&#40;23&#41;
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

I really wouldn't recommend learning C or C++ programming on a PSP - try writing some small command line programs first.
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

I was looking at your questions again... I noticed something after I posted last time.

you wrote:
everytime i put a number in side the sceDisplayScreenWaitVblankStart('here'), i get:

Code: Select all

main.c&#58;197&#58; error&#58; too many arguments to function 'sceDisplayWaitVblankStart'
the "Screen part at the top is obviously just a typo, but the important thing is the function.

If you look at the pspdisplah.h file, it will tell you the way the functions have been defined.

in the case of sceDisplayWaitVblankStart() it is:

Code: Select all

/**
 * Wait for vertical blank
 */
int sceDisplayWaitVblankStart&#40;void&#41;;
so it doesnt actually take any integers. you simply call:

sceDisplayWaitVblankStart();

do a text search for sceDisplayWaitVblankStart in the folder of the pspsdk and you will see many examples of "main.c"

Cheers,

HaQue[/code]
sandberg
Posts: 90
Joined: Wed Oct 05, 2005 1:25 am
Location: Denmark

Post by sandberg »

You can find two free books which'll teach you more or less anything about C++ from the link below.

http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html
Br, Sandberg
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

ok that helps. ill just look around the pspdev folder, so

im also looking for an analog usage program/game with soruce code so i can learn how to use hte analog a bit better, all i know is pad.lx and pad.ly so please help
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

P>S> im on the schools computers right now, good thing thye dont bock forums.ps2dev.org lol

anyways, i just need some souyrce code that includes all the basic functions and things that i could learn alot from, so ill just look around, but if i get a SERIOUS problem meaning an error that is invisible or something or cygwin messses u, then ill ome back and ask some questions
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

just getting source code and nailing it together to get what you want working is not a very good idea. you won't grasp the basics and will actually take longer to learn.

You also will be dealing with many programming styles of all the authors of the code you use and alot of them will have bad programming style that you could pickup.

While theres nothing wrong with using others source code (dont re-invent the wheel) You should try programming a few things from scratch and get to learn the basics first.

This is the knowledge that will help you fix programming errors quickly.

I know it is hard when you start out because you just want to program stuff and not do hello world's and the like. It does take a bit of time, and Im sure alot of people try for a few days and just forget it. It is worth the extra time.

Its like wanting to bake cakes. You buy the "packet mix" of 10 different brands and make 10 nice cakes. You still don't know how to make cakes though.

HaQue
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

well if you go to www.pspupdates.com, youll see that i made one of my own little games called stopper 69 and i made it from 1/2 scratch, the other the lesson with the timer, but i kno how to make a timer and such, im just working with functions and trying to get what i want to happen, happen, i just dont know some of the basic rules, like hte return 0, but now i understand it after reading this, now i just need to kno what arguments can be held in the sceDsiplayScreenWait('here'), so i cna have a 10 second pause(600 vblanks), just need to find out how some things work,but now that i kno i can look in the pspdev folder for the function examples and such, i should ahve no problems

for example, i just looked in the 'include' fodler and saw a math.h so i pen ed it up and i found that 'M_PI' is wha is needed to print out or use pi.
HaQue
Posts: 91
Joined: Fri Nov 25, 2005 8:52 am
Location: Adelaide, Australia
Contact:

Post by HaQue »

cool, it really sounds like you are going ok with it all. I would still try and pickup as much of the basics as you can. Good Luck with it all too.

BTW, couldnt find Stopper 69 on the site. I was interested to see what sort of game and check it out.
*EDIT* found the file...

HaQue
sg57
Posts: 144
Joined: Fri Oct 14, 2005 2:26 pm

Post by sg57 »

ya theres a major bug in it im gonna fix that perfect just to get even more experience, ill make a function thatll repeat the entire program back to the start, (got it done) put a sceDisplayScreenWait(); to make hte 'WINNER' stay when you stop on 69 (that was the major bug, orese it just flashed the Winner sign and thne keeps counting) and for some reason i have this scrolling of my text, so i put it into a functiuon and ill have SQUARE load the scrolling demo and X load the main progmra(stopper 69), im just havintg this one problemn with my functions if any one could answer them, and no im not asking for code, im just aksing how to fix loading my fucntion, ok this is what happens...

i have text appear as a main menu sorta, and if you press square, you load hte scrolling demo, and cross for the stoipper 69 game, now both of these functions work but only for like a second and thast right at the beginning when its loading still (meaning if the orange light is blinking when laoding and you hold/press square/cross, itll do that function) but not any other time, i have the text in a loop so that when i load my function, its in a loop, but i cant seem to get my functins to load no matter when on the main screen, but ill keep trying and i dont want to request for code orelse i wont learn like HaQue said, im just asking for advice on how to get my functions to load for ever instead of just when its loading up the entire program..

thanks HaQue
Post Reply