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; Zitat von _dysfunctional This is what we are talking about. You can't just expect us to write and fix code ...
-
11-30-2008, 07:01 PM #9271QJ Gamer Bronze
- Registriert seit
- Aug 2008
- Ort
- thugz mansion
- Beiträge
- 875
- Points
- 5.594
- Level
- 48
- Downloads
- 0
- Uploads
- 0
I did actualy and these are all of my includes
#include <pspdebug.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspthreadman.h>
#include <stdlib.h>
#include <string.h>
#include <psputilsforkernel.h>
#include <psppower.h>
#include <malloc.h>
#include <pspsdk.h>
#include <stdarg.h>
#include <pspdisplay.h>
#include <pspkerneltypes.h>
#include <psptypes.h>
#include <stdint.h>
#include <graphics.h>
#include <pspusb.h>
#include <pspsysevent.h>
#include <pspatrac3.h>
#include <pspwlan.h>
Every time i hear of an include i add it to all of my projects even if not neede.
I mentioned the wrong one by accident.
And im asking no one to write anything and also i do know where my includes are. ther @ C:\pspsdk\psp\sdk\include
and also before you say this i did put the route to the lib in my makefile.
So far with the project im working on since its very simple know exactly what im doing and i found the problem for myself. The lib was bad i replaced it and know it works.
Dont know what ****ed it up but its working now.
Zitat von SuperBatXS
-
11-30-2008, 07:14 PM #9272QJ Gamer Gold

- Registriert seit
- Jul 2005
- Ort
- everywhere
- Beiträge
- 3.526
- Points
- 17.453
- Level
- 84
- Downloads
- 1
- Uploads
- 0
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
-
11-30-2008, 08:13 PM #9273QJ Gamer Bronze
- Registriert seit
- Aug 2008
- Ort
- thugz mansion
- Beiträge
- 875
- Points
- 5.594
- Level
- 48
- Downloads
- 0
- Uploads
- 0
-
11-30-2008, 09:13 PM #9274lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
-
12-01-2008, 02:20 AM #9275QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
While you are getting away with this now, this is a bad habit to get into as include more files adds to compiling time especially if they header files that get modified. E.g.
B.h includes A.h. B.cpp includes B.h. C.cpp includes B.h.
This means that when A.h gets changed, both B.cpp and C.cpp needs to be compiled as they have a dependency on A.h.
Always try to include the minimum number of headers.[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]
-
12-01-2008, 12:56 PM #9276QJ Gamer Bronze
- Registriert seit
- Aug 2008
- Ort
- thugz mansion
- Beiträge
- 875
- Points
- 5.594
- Level
- 48
- Downloads
- 0
- Uploads
- 0
i dont plan on doing any big programs for psp any time soon there all simple stuff that are not [release] quality in my opinion i just do this for simple stuff and i hardly ever edit my header files nor other includes that goes with them.
Mostly because i cannot use the scanf function and alot of other functions i use for programing on the pc.
Zitat von SuperBatXS
-
12-06-2008, 07:23 PM #9277QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
I haven't coded in a bit and I'm starting to get into it. Came across A_noob's ConfParser last night which has saved me having to right up my own. Everything's been going fine except when I've tried to load a sound file with OSLib.
The entry from my config file I'm reading:
Then I'm using this to load the file:Code:kitDir=kit1
However it crashes when it goes to load. Probably something simple I'm missingCode:char *file; sprintf(file, "Sounds/Drums/%s/snareon.wav", stringValueFromName("kitDir", config)); snareOn = oslLoadSoundFile(file, OSL_FMT_NONE);
-
12-06-2008, 08:41 PM #9278QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- USA SC/NC
- Beiträge
- 699
- Points
- 5.712
- Level
- 48
- Downloads
- 0
- Uploads
- 0
[CODE]Random Facts:
irc://irc.malloc.us #wtf #**********
[/CODE]
[SIZE="6"][FONT="Century Gothic"][COLOR="Blue"][URL="http://forums.**********.net"]http://forums.**********.net[/URL][/COLOR][/FONT][/SIZE]
-
12-07-2008, 12:38 PM #9279I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm trying to get a global object, I've searched Google and found the method singleton, but in all honesty its not making any sense to me. I was wondering if someone knew of a good link explaining well, or could throw me some commented code giving me an idea what to do. From what I can see, I lose use of the constructor?
-Aura
-
12-07-2008, 02:08 PM #9280QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
There are other ways to do it, but this is safer, and pointer-free.Code:class Singleton { private: static Singleton m_mySingleton; // Our single instance of the class protected: Singleton() { } // We don't want people calling these, but we want them to be easily ~Singleton() { }; // subclasses public: static Singleton& Instance() // Our way of getting the instance { return m_mySingleton; } void DoSomething() { std::cout << "I did something.\n"; } // A member function };
// Somewhere else...
Singleton::Instance().DoS omething(); // "I did something."
-
12-07-2008, 03:09 PM #9281I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Ok, I think I understood that, but is it then not possible to create multiple objects? Or would I have to create multiple instances in the same class?
-Aura
-
12-07-2008, 03:27 PM #9282QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
You are trying to access a global object?
Code:class Blah { // Some code }; Blah gGlobalBlah; int main() { gGlobalBlah.SomeFunction(); // global objects accessed }[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]
-
12-07-2008, 03:35 PM #9283I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yes, but I'm doing it over a few source files, which is causing my application to crash from what I can tell.
-Aura
-
12-07-2008, 04:00 PM #9284QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Look up the extern keyword
Code:// blah.h #ifndef BLAH_H #define BLAH_H class blah { // some code }; extern blah gGlobalBlah;Code:// blah.cpp #include "blah.h" blah gGlobalBlah; // some code
Code:// main.cpp #include "blah.h" int main() { gGlobalBlah.SomeFunction(); // global access to this variable }[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]
-
12-07-2008, 04:10 PM #9285I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I was using extern.
When I remove all calls to the objects except in the function that uses it the most, and when I "create" the object within that function, everything runs fine (appart from none of the other code functioning correctly). I also commented all my functions, but "created" the objects in the global source, and used extern in the header with the ifndef, define, endif, and it still crashes, so I know its not my code but rather the way I'm making my objects global.
-Aura
EDIT:
I have to apologise, turns out I hadn't done something, still not 100% sure what it was, I did a couple of things including remove the constructor, and now it works as its supposed to without crashing.Geändert von Auraomega (12-07-2008 um 05:16 PM Uhr)
-
12-07-2008, 08:10 PM #9286QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
What was in the constructor and what do you mean by 'create'?
[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]
-
12-08-2008, 06:36 AM #9287I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I just initialised the private memebers, and called another function not in the class. And by create I mean
I couldn't think of the word last night and I'm doing no better now either.Code:class blah { ... }; blah meh;
-Aura
-
12-08-2008, 06:53 AM #9288QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Did you attempt to call a virtual function in the constructor? Or a system function (such as initialising the GU or loading a texture)?
And the word the you are looking for is define or class definition.[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]
-
12-08-2008, 07:21 AM #9289I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yeah I used a system function, is that not a good thing to do? And thanks, I thought defination but thought I'd got confused with precompilers.
-Aura
-
12-08-2008, 07:50 AM #9290QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
It is fine to but this highlights the problem with globals. All globals are instantiated before the program even runs the first line of code in main. This means that the constructors of all global objects are called first so if it uses a system function that relies on something else being initialised first, then this will cause problems.
There are several ways round this:
- Don't use globals (which is not always possible)
- Use a two stage initialisation process (e.g. have another function called Init which gets called at the right time)
- Other variations of the above[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]
-
12-08-2008, 08:03 AM #9291I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Thanks I see what you mean now, although I knew they were instantiated before the rest, it hadn't occured to me that it would be calling a function which wasn't yet available. I changed my constructor to an init function last night which worked, but I'm happier now I know why it worked.
-Aura
-
12-08-2008, 10:00 AM #9292Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
sceIoUnassign("flash0");
sceIoAssign("flash0", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);
This returns <0 on my 5.00M33 psp , i'm working in kernel mode , anyone knows what's wrong? It should just assign flash0 and make it writeable
-
12-08-2008, 10:55 AM #9293
-
12-08-2008, 11:25 AM #9294Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
:/ , thnx
but now:
int createdFile = sceIoOpen("flash0:/vsh/resource/gameboot.pmf", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
returns a negative number , although I was able to assign flash0 (it returns 0 now)
-=Double Post Merge =-
Solved the problem , the file was read-only :)Geändert von hallo007 (12-08-2008 um 12:23 PM Uhr) Grund: Automerged Doublepost
-
12-09-2008, 07:03 AM #9295QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
I just reinstalled toolchain and got oslib set up again and everything, but classes seem to be broke :\
I'm stumped, does anyone have any ideas?
makefile:
main.cpp:Code:TARGET = Test OBJS = main.o YOURLIBS= INCDIR = CFLAGS = -G4 -Wall -O2 CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti ASFLAGS = $(CFLAGS) LIBDIR = LDFLAGS = STDLIBS= -lstdc++ -losl -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm LIBS=$(STDLIBS)$(YOURLIBS) EXTRA_TARGETS = EBOOT.PBP PSP_EBOOT_TITLE = Test PSPSDK=$(shell psp-config --pspsdk-path) include $(PSPSDK)/lib/build.mak
TestClass.hCode:#include <oslib/oslib.h> #include "TestClass.h" PSP_MODULE_INFO("Module name", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); int main(int argc, char* argv[]) { TestClass testclass; return 0; }
TestClass.cppCode:#ifndef TESTCLASS_H #define TESTCLASS_H class TestClass { public: TestClass(); ~TestClass(); }; #endif
Code:#include "TestClass.h" TestClass::TestClass() { } TestClass::~TestClass() { }
error:
Code:psp-g++ -I. -I/usr/local/pspdev/psp/sdk/include -G4 -Wall -O2 -I. -I/usr/local/pspdev/psp/sdk/include -G4 -Wall -O2 -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o main.o main.cpp psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -G4 -Wall -O2 -D_PSP_FW_VERSION=150 -L. -L/usr/local/pspdev/psp/sdk/lib main.o -lstdc++ -losl -lpng -lz -lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o Test.elf main.o: In function `main': main.cpp:(.text+0x8): undefined reference to `TestClass::TestClass()' main.cpp:(.text+0x10): undefined reference to `TestClass::~TestClass()' collect2: ld returned 1 exit status make: *** [Test.elf] Error 1
Any help would be appreciated.
-
12-09-2008, 07:11 AM #9296QJ Gamer Bronze

- Registriert seit
- Sep 2006
- Ort
- france
- Beiträge
- 170
- Points
- 6.359
- Level
- 52
- Downloads
- 0
- Uploads
- 0
-
12-09-2008, 07:55 AM #9297QJ Gamer Bronze

- Registriert seit
- Jul 2006
- Beiträge
- 550
- Points
- 5.381
- Level
- 47
- Downloads
- 1
- Uploads
- 0
Wow, I can't believe I missed something as silly as that.
Thanks, I guess I've spent too much time out of C++ :-(
-
12-09-2008, 03:39 PM #9298QJ Gamer Blue
Achievements:
- Registriert seit
- Aug 2008
- Beiträge
- 26
- Points
- 2.426
- Level
- 29
- Downloads
- 0
- Uploads
- 0
Just wildcard everything, makes it much easier.
-
12-10-2008, 06:16 AM #9299QJ Gamer Green
- Registriert seit
- May 2008
- Ort
- The Netherlands
- Beiträge
- 330
- Points
- 3.567
- Level
- 37
- Downloads
- 0
- Uploads
- 0
Hey guys can someone help me out? I want to learn C++, but I having a little problem with installing the psptoolchain. I'm did everything from the tutorial of psp-programming.com but when I want to install the psptoolchain it gives me some errors. I am from the Dutch so I don't understand that errors. Can someone help me out?
Here's the error:
-
12-10-2008, 06:25 AM #9300QJ Gamer Silver
- Registriert seit
- Sep 2006
- Ort
- Perth, Scotland
- Beiträge
- 1.094
- Points
- 8.475
- Level
- 62
- Downloads
- 0
- Uploads
- 0
You need to setup your enviroment variables before you start installing.


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