Zeige Ergebnis 5.461 bis 5.490 von 10174
C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Well, what are the errors?...
-
07-13-2007, 04:04 AM #5461It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Well, what are the errors?
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 04:30 AM #5462QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Zitat von Archaemic
Below is the whole code for the project (Yes i know it does pretty much sod all right now but I just need to set the basics up and get everything moving).Code:$ make psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION= 150 -c -o main.o main.c main.c: In function 'main': main.c:31: error: syntax error before '&' token main.c: At top level: main.c:57: error: syntax error before '&' token main.c: In function 'FPS': main.c:59: error: 'fps' undeclared (first use in this function) main.c:59: error: (Each undeclared identifier is reported only once main.c:59: error: for each function it appears in.) main.c:60: error: 'fpsTickNow' undeclared (first use in this function) main.c:62: error: 'fpsTickLast' undeclared (first use in this function) main.c:62: error: 'tickResolution' undeclared (first use in this function) main.c:65: error: 'fpsDisplay' undeclared (first use in this function) make: *** [main.o] Error 1
Code in Graphics.h is optimised, contains a few extra functions and mostly uses the GU, but that doesn't seem to be the error, and i've used this code plently of times before....Code:#include <malloc.h> //For memalign() #include <pspkernel.h> #include <pspdisplay.h> #include <pspdebug.h> #include <stdio.h> #include <pspcallbacks.h> #include <pspgu.h> #include <pspgum.h> #include <psprtc.h> // for the timer/fps functions #include "graphics.h" #define BUF_WIDTH (512) #define SCR_WIDTH (480) #define SCR_HEIGHT (272) PSP_MODULE_INFO("Breakout", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER); void *fbp0; int main(int argc, char **argv) { int fps = 0; // for calculating the frames per second char fpsDisplay[100]; u32 tickResolution; u64 fpsTickNow; u64 fpsTickLast; void FPS(int&, char*, u32&, u64&, u64&); // Display Frames Per Second initGraphics(); pspDebugScreenInit(); SetupCallbacks(); sceRtcGetCurrentTick( &fpsTickLast ); tickResolution = sceRtcGetTickResolution(); while(1) { FPS(fps, fpsDisplay, tickResolution, fpsTickNow, fpsTickLast); flipScreen(); } sceGuTerm(); // Terminating the Graphics System sceKernelExitGame(); // Quits Application return 0; } void mainMenu() { } void FPS(int& fps, char* fpsDisplay[], u32& tickResolution, u64& fpsTickNow, u64& fpsTickLast) { fps++; sceRtcGetCurrentTick( &fpsTickNow ); if(((fpsTickNow - fpsTickLast) / ((float)tickResolution)) >= 1.0f) { fpsTickLast = fpsTickNow; sprintf( fpsDisplay, "FPS: %d", fps ); fps = 0; } pspDebugScreenSetOffset( (int)fbp0 ); pspDebugScreenSetXY( 0, 0 ); pspDebugScreenPrintf( fpsDisplay ); }
-
07-13-2007, 04:35 AM #5463It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You've got a forward declaration in the middle of a function. You can't do that. Move it above the main function.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 04:46 AM #5464QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I'm not with ya. Whats a forward declaration ?
Zitat von Archaemic
-
07-13-2007, 05:03 AM #5465QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
You've got this in the middle of your main function:
Move it *outside* of the main function (above it).Code:void FPS(int&, char*, u32&, u64&, u64&);
[I fail @ life]
-
07-13-2007, 05:06 AM #5466QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
why would that matter?
Zitat von FreePlay
I'd got a program with around 10 Function Delcarations in the main() function..
I Don't get it... I was always told put function declarations before you use the function, not in global territory.
EDIT - I Moved it, same error..
-
07-13-2007, 05:07 AM #5467It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yes, before you use the function...but it has to be global.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 05:08 AM #5468QJ Gamer Green
- Registriert seit
- Sep 2006
- Ort
- Cape Town, South Africa
- Beiträge
- 714
- Points
- 5.795
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I need to know this. I have an array on the heap like this:
How do I free this array? Will simply calling free(throwables) work or do I have to do something else?Code:// (Throwable is a struct) int numThrowables ; Throwable* throwables ; // ... numThrowables = /* some value unknown at compile time */ throwables = malloc(sizeof(Throwable) * numThrowables) ;
-
07-13-2007, 05:08 AM #5469QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
im making a snake game, i can get a snake that is 5 blocks long to move around the screen using the directional buttons. Ive tried to make it add blocks to the snake but i cant seem to make it work correctly. Im not going to post the code, because its not the codr that is the problem. Here's what the situation is:
The snake starts like this: (H = head, b# = body part)
then when it moves the head moves forward and b4 goes to the old position of the head:Code:b4 b3 b2 b1 H
The body parts are an array of structures that hold the X and Y coords of themsleves. The snake length variable holds the length of the snake and during run time, each part of the snake is blitted to the screen according to the co-ordinates it hold. Now, heres where i ran into the problem. When i add a new part of the body, it has to insert it at the end of the array, meaning there is only one position that it will add the block instantly. For example: (F = Food)Code:b3 b2 b1 b4 H
The new block overlaps the old one and the snake only appears longer when the snake is at is original state:Code:b2 b1 b4 b3 H F -> b2 [b1b5] b4 b3 H
So, there you have it, does anyone know the solution to this problem or have made a snake game themselves?Code:b5 b4 b3 b2 b1 H
PS: if you really want to look at the code, here it is:
Spoiler for Code:...Just Returned To The Scene...
-
07-13-2007, 05:09 AM #5470QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Well, I changed it, and same error. Function Declarations do not have to be global either.
Zitat von Archaemic
-
07-13-2007, 05:10 AM #5471It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
free is how you do it. The size allocated with malloc is know to the free function.
Zitat von coolguy5678
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 05:11 AM #5472QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Yeah, im sure free() will work.
Zitat von coolguy5678
...Just Returned To The Scene...
-
07-13-2007, 05:12 AM #5473It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Yeah, not in the case of private member functions. But that's only in C++.
Zitat von MiG
AFAIK, in C, all functions are global scope.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 05:13 AM #5474QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
ok question why is atan2 messing up my other units?
ok here's whats hapeening:
Spoiler for code:
i determined it was the 2 atan2 commands which well screw up my units here's what i mean:
i select a unit any unit who hasen't been looped though well just jump to random locations on the screen and i don't know why
i hope i managed to get my problem across clearly and hope someone can help me1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-13-2007, 05:14 AM #5475QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
anyone wanna take a look at my problem on the previous page?
...Just Returned To The Scene...
-
07-13-2007, 05:16 AM #5476QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
Right, ok. I've only really studied C++ so thought it was the same for C. I've now switched to C++ for the main file and now get the original error i was getting, the undefinded reference.. blah blah.
Zitat von Archaemic
-
07-13-2007, 05:21 AM #5477It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I checked, and the lines don't seem to match up with the errors they raise.
But you still can't do what you did in C++. I say private members, and that isn't a member at all, nor where you're defining it would ever be a member.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 05:34 AM #5478QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I've got a Full Pacman style game here written in C++ for the Console on the PC, and that compiles with function declerations just fine.
Zitat von Archaemic
I'm pretty sure you can or surely my code wouldn't work ?
And I know, the errors just don't match up to the Code, it sucks.
-
07-13-2007, 05:49 AM #5479QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I'm pretty sure you can't use & in a function param... what are you trying to do, get the address of the argument? If so, you have to use * instead, and use & on the value you pass *into* the function so you're passing its address.
Zitat von MiG
If you only ever use the locally-declared functions in the function where they're declared, it will probably work.
Zitat von MiG
But declaring non-dynamically-located functions locally is generally a stupid idea... I have no idea who taught you to do that, but you should kick them hard in the shins.[I fail @ life]
-
07-13-2007, 05:50 AM #5480It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Um, FreePlay, it's called passing by reference. Qt does it ALL THE TIME, so it must be valid.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 06:26 AM #5481QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
any1 for my prob?
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-13-2007, 06:55 AM #5482QJ Gamer Blue
- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 499
- Points
- 5.848
- Level
- 49
- Downloads
- 0
- Uploads
- 0
I've got my project compiling now... I Have no idea why but i tried the extern thing again, and it worked :|
I swear it never worked before. :|
-
07-13-2007, 07:24 AM #5483QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
hmmm...odd my prob just kinda disappeared i went back to my last setup and it still works fine i guess nvm now that it's working
-= Double Post =-
in the oslib what is the command to place a pixel i can only find the one's to draw lines,rectangles,and imagesGeändert von slicer4ever (07-13-2007 um 07:46 AM Uhr) Grund: Automerged Doublepost
1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-13-2007, 07:49 AM #5484QJ Gamer Green
- Registriert seit
- Jul 2007
- Beiträge
- 88
- Points
- 3.606
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Can anyone help me?
(page 546)
-
07-13-2007, 07:58 AM #5485QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
after a quick scan right here:
if(box.state==1 && box.jumpspeed==0)
{ box.y=box.y-0.8;
box.jumpspeed+=0.3;}
once the jumpspeed changes it doesn't again so it stays at that variable and a look into your code you probably want to change this to:
if(box.state==1 && box.jumpspeed<3.5)
{ box.y=box.y-0.8;
box.jumpspeed+=0.3;}
edit:
actually looking at it further you probably just want to drop the jumpstate and change it to:
if(box.state==1)
{ box.y=box.y-0.8;
box.jumpspeed+=0.3;}
ok after reading a little bit more this is what i think your fully after:
if(box.state==1 && box.jumpspeed<3.5)
{ box.y=box.y-0.8;
box.jumpspeed+=0.3;}
if (box.state==1 && box.jumpspeed>3.5)
{box.y=box.y-0.3;
//new line here to keep the jumpspeed increasing
box.jumpspeed+=0.3;}
if (box.state==1 && box.jumpspeed>=5);
{
box.state=2;
}1. Failed....again...
2. http://slicer.gibbocool.com/ stay updated on all my projects
3. it'll be 5 years in june, that's nearly 1/4 of my life on this planet that i've visited these forums, what a ride it has been
-
07-13-2007, 11:35 AM #5486QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
Yes. I realize that. I meant that in the function *declaration* I don't think it's possible to use & on one of your args, e.g. "void doSomething(char &x)". I know you can pass something by reference like this:
Zitat von Archaemic
and slicer, I already told him that.Code:int main() { int a,b; a=5; b = 7; foo(&a, &b); printf("%d %d\n", a,b); } void foo(int *x, int *y) { *x = 6; *y = 8; }Geändert von FreePlay (07-13-2007 um 11:37 AM Uhr) Grund: Automerged Doublepost
[I fail @ life]
-
07-13-2007, 11:50 AM #5487QJ Gamer Silver

- Registriert seit
- Jan 2006
- Ort
- Germany
- Beiträge
- 926
- Points
- 14.087
- Level
- 77
- Downloads
- 0
- Uploads
- 0
No, C++ really supports the ampersand as parameter modifier to mark it as "by reference" without making it a pointer (ie it's safer as it cannot be null and avoids all the pointer-pitfalls).
See f.e. http://www.tech-recipes.com/c_programming_tips1232.htmlRaphs board rules #31: Excessive use of punctuation is either a sign of a lesser ego or a small mind. Avoid it if you don't want to look like a total moron.
Raphs board rules #17: When you need to ask whether you are capable of doing something, you are not.
Raphs board rules #2: Exploits aren't found by changing version numbers, blindly merging data into a file or turning your PSP upside down.
Raphs board rules #1: If you have no clue how exploits work, don't come up with ideas about them.
-
07-13-2007, 01:48 PM #5488QJ Gamer Platinum
- Registriert seit
- Dec 2005
- Ort
- h0000000rj
- Beiträge
- 12.867
- Points
- 57.528
- Level
- 100
- Downloads
- 0
- Uploads
- 0
rrrrrreallly.
well, I do mostly C, anyways.[I fail @ life]
-
07-13-2007, 04:29 PM #5489It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
I'm fairly certain you can do it in C, too, but I'm not sure.
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
07-13-2007, 04:49 PM #5490QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, you can only pass by pointer in C.
Zitat von Archaemic
Edit: I stand corrected. I just tried this an you can pass by reference in C.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]


LinkBack URL
About LinkBacks
Mit Zitat antworten

Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum