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; unsigned char 0 - 255 signed char -127 to 127 when you just say char , it will be signed...
-
08-20-2007, 03:32 AM #6181Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
unsigned char 0 - 255
signed char -127 to 127
when you just say char , it will be signed
-
08-20-2007, 03:42 AM #6182I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yup, I sorta solved that problem last night (wasn't because I'd left the #include "global.h").
Zitat von pspballer07
Now though, when I type global.variable, it says its unrecognised.
-Aura
-
08-20-2007, 05:30 AM #6183Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
warning: accordances are lacking around beginning valueCode:typedef struct { int data[50]; }DATEBUFFER; //some code DATABUFFER someInfo = { 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xB4 , 0x25 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0XFF , 0xFF , 0xFF , 0xCC , 0x00 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x3C , 0x83 , 0x00 , 0x00 , 0xFF , 0xFF };
warning: (near initialization for ‘someInfo.data’)
-
08-20-2007, 05:39 AM #6184QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
You've only initialized 36 variables? I'm not sure what the actual problem is though...
...Just Returned To The Scene...
-
08-20-2007, 05:40 AM #6185Heroes never die

- Registriert seit
- Aug 2006
- Ort
- ...........
- Beiträge
- 1.323
- Points
- 8.645
- Level
- 62
- Downloads
- 0
- Uploads
- 0
I dont understand the two warnings , that's the problem
-
08-20-2007, 05:45 AM #6186It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
signed char is -128 to 127.
Zitat von hallo007
Zitat von hallo007
Note the changes.Code:typedef struct { int data[50]; } DATABUFFER; //some code DATABUFFER someInfo = { { 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xB4 , 0x25 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0XFF , 0xFF , 0xFF , 0xCC , 0x00 , 0x00 , 0x00 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x3C , 0x83 , 0x00 , 0x00 , 0xFF , 0xFF } };
Also, I don't know if this will work because it doesn't initialize the whole array.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
08-20-2007, 11:34 AM #6187
pointer targets differ in signedness;
What does that mean?
-
08-20-2007, 11:42 AM #6188QJ Gamer Green
- Registriert seit
- Apr 2006
- Ort
- England ~¦¦¦|+|¦¦¦~
- Beiträge
- 1.112
- Points
- 9.165
- Level
- 64
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Im guessing its something todo with UNSIGNED and SIGNED variables... The two targets aren't the same 'signedness'.
Zitat von Mr305
Geändert von JaSo PsP (08-20-2007 um 03:23 PM Uhr)
...Just Returned To The Scene...
-
08-20-2007, 03:33 PM #6189
"pointer targets differ in signedness" generally means you are trying to point a unsigned char pointer at signed char data or vice versa.
Heres an example that would generate this warning/error message:
It could be more complicated but it will boil down to something like this happening. I'm pretty sure the above code wouldn't compile.Code:char variable; unsigned char* variable_ptr = &variable;
To avoid it you could use a type cast, but it could be bad because 'variable' might contain value -121 but if you access it through 'variable_ptr' it will give you value 135.
Example:
The above code would print '135' even though you set the value to -121.Code:char v = -121; unsigned char* v_ptr = (unsigned char*)&v; printf( "%d", *v_ptr);
Hope that helps.
If an initialiser list is smaller than the array, the rest of the array is filled with 0 so it shouldn't be a problem.Also, I don't know if this will work because it doesn't initialize the whole array.
-
08-20-2007, 06:51 PM #6190
are you serously typing "global.variable" or "global.(insert var here)"
Zitat von Auraomega
Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-21-2007, 12:30 AM #6191
We might need to see some code to sort out the problem, but if I had to guess I would say that you haven't actually declared a variable called global.
Underneath were you define the global struct you need to declare a variable of that type.
ie.
Just a guess :), if not show a little code and someone will figure it out.Code:typedef struct { int a, b, c, d; } Global; extern Global global; // <- This bit
-
08-21-2007, 05:59 AM #6192Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
apologies, wrong thread
-
08-21-2007, 03:31 PM #6193I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Hi, nah even I'm not that stupid (I think...), I noticed that the code you sent me was causing an error, so I slightly modified it, solved it not long after making that post... I'm just getting into the habit of not editing posts lately.
Zitat von pspballer07
I'm STILL stuck on using GU in the XMB, its driving my nuts now, I've made a post on ps2dev, and no-one has replied. Has anyone got any idea how I can do something even as simple as one of the samples in the XMB without it crashing?
-Aura
-
08-21-2007, 03:45 PM #6194QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
:o Yes.
Zitat von Auraomega
-
08-21-2007, 03:47 PM #6195I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Argh, maybe some source code or something would be handy... I've tried looking at the DSX code, and either I'm missing some code, or I'm stupid, because I really can't see how it works, at all.
Zitat von _dysfunctional
-Aura
-
08-21-2007, 03:55 PM #6196QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Well, you post some code and we will see if we can work out your problems.
For future reference, coming to #psp-programming IRC channel will get you much faster results than posting here. It is on irc.freenode.net. I would suggest the clients, Xchat, Konversation, *****X, or mIRC.
-
08-21-2007, 04:05 PM #6197I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
The code I'm using currently is the exact same peice in the samples (logic), I just changed little bits. I'm using that code because I know its made by someone who knows what their doing, once I get that working I'll change the bits I can to do what I want.
Zitat von _dysfunctional
As for the IRC channel, I might give that a shot, cheers.
-Aura
-
08-22-2007, 12:20 PM #6198
haha k.
Zitat von Auraomega
What did u fix? (so I know for the future)Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-22-2007, 12:31 PM #6199I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Zitat von pspballer07
This is the code you said
I simply changed it to...
Zitat von pspballer07
I noticed that this was how it was done by taking a look at a couple of the files in the include folderCode:typedef struct { float Varf; }Global;
-Aura
-
08-22-2007, 04:09 PM #6200
Are you sure that was the problem?
andCode:typedef struct Global { // whatever variables };
are both perfectly legal and should give the same result.Code:typedef struct { // whatever variables } Global;
And to be able to access the member variables of a structure there must be an instance of it, which is why you will need to declare a global variable of type 'Global'.
If you want several files to all be able to access the same global variables, you will need to add this line of code after the structure definition.
Otherwise there will be no common instance of the global across all the files.Code:extern Global global;
-
08-22-2007, 05:54 PM #6201
@auraomega: that shouldn't make a difference. it works the same way
@psp_jono: I did tell him that "extern Global global;" needs to be in there. He has it in but didn't put that part.Current releases:
Icon Action Replacer v1.5- latest release
Current projects:
PSP C++ IDE - Currently v1.6
RPG Paradise - Latest version at my website
-
08-22-2007, 06:40 PM #6202
Yeah, that post wasn't actually meant for you, I was telling Auraomega because I thought he had removed it.
Zitat von pspballer07
-
08-22-2007, 10:20 PM #6203QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
:o
Zitat von psp_jono
I wouldn't be to sure, mate.
Gives me:Code:#include <stdio.h> typedef struct ThisWontWork { int myVar; int myOtherVar; }; int main(int argc, char* argv[]) { ThisWontWork myStruct; myStruct.myVar = 1; myStruct.myOtherVar = 1; return 0; }
[email protected]:~/.temp/jono_struct$ gcc main.c -o typedef_struct
main.c:7: warning: useless storage class specifier in empty declaration
main.c: In function ‘main’:
main.c:11: error: ‘ThisWontWork’ undeclared (first use in this function)
main.c:11: error: (Each undeclared identifier is reported only once
main.c:11: error: for each function it appears in.)
main.c:11: error: expected ‘;’ before ‘myStruct’
main.c:12: error: ‘myStruct’ undeclared (first use in this function)
BUT, this compiles and runs fine.
Code:#include <stdio.h> typedef struct ThisWontWork { int myVar; int myOtherVar; } ThisWontWork; int main(int argc, char* argv[]) { ThisWontWork myStruct; myStruct.myVar = 1; myStruct.myOtherVar = 1; return 0; }
-
08-22-2007, 10:59 PM #6204
Strange, I jut tested it on a small gcc compiler on my pc and it compiled and ran without a problem.
Here is the code, like I said it compiles and runs fine.
I guess it must be a difference in the standards used by the pc compiler I'm using and the psp-gcc compiler.Code:#include "stdio.h" typedef struct { int a; } Example1; typedef struct Example2 { int a; }; Example1 global1; Example2 global2; int main() { global1.a = 1; global2.a = 2; printf( "Global: %d\nGlobal2: %d", global1.a, global2.a); return 0; }
Thanks, always handy to find these things out.
I should've tested on the psp first :)
-
08-22-2007, 11:06 PM #6205QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Hm, I compiled the above example in my post with GCC 4.1.2 Ubuntu Linux. Now, I just tried to compile the same example for the psp, and I get:
[email protected]:~/.temp/jono_struct$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -G0 -Wall -D_PSP_FW_VERSION=150 -c -o main.o main.c
main.c:10: warning: useless storage class specifier in empty declaration
main.c: In function ‘main’:
main.c:14: error: ‘ThisWontWork’ undeclared (first use in this function)
main.c:14: error: (Each undeclared identifier is reported only once
main.c:14: error: for each function it appears in.)
main.c:14: error: expected ‘;’ before ‘myStruct’
main.c:15: error: ‘myStruct’ undeclared (first use in this function)
make: *** [main.o] Error 1Hm, I'm interested to know which version of GCC you tried compiling with[email protected]:~/.temp/jono_struct$ psp-gcc --version
psp-gcc (GCC) 4.1.0 (PSPDEV 20060507)
-= Double Post =-
Ahah! It looks like it is only valid in C++. :PGeändert von _dysfunctional (08-22-2007 um 11:11 PM Uhr) Grund: Automerged Doublepost
-
08-22-2007, 11:19 PM #6206
Hmm, I guess it must just be the standard that the compilers adheres to, some standards must be a bit more relaxed.
I use the above basically all the time. It must be the most acceptable to the different standards because I've never had a problem with it.Code:typedef struct { // member vars } Structure;
The only exception is if I have a self-referential structure, in which case I just typedef the struct name later.
ie.
EDIT: Ahh. I jut saw your footnote and yep you are correct, I'm using a c++ compiler. I didn't even realise :).Code:struct example { struct example* a; }; typedef struct example Example;
Its a small program called jens file editor, it came with a built in gcc compiler.
-
08-22-2007, 11:21 PM #6207QJ Gamer Blue
- Registriert seit
- Jul 2007
- Beiträge
- 296
- Points
- 3.795
- Level
- 38
- Downloads
- 0
- Uploads
- 0
Well, you could do:
I believe that would work.Code:typedef struct _myStruct { _myStruct* s; } myStruct;
-
08-23-2007, 12:45 AM #6208
struct tagnameforcompiler {
int variable1;
int variable2;
char variable3;} declarestructvariable1, declarestructvariable2;
declarestructvariable1.va riable1 = 10;
declarestructvariable2.va riable3 = 'C';
-
08-23-2007, 02:39 AM #6209
I've never seen a self-referential structure defined like that, much better than seperating the typdef from the structure definition. Thanks :)
Zitat von _dysfunctional
-
08-24-2007, 03:21 PM #6210
what is the function to erase the entire nand. no i am not making a bricker (pointless becasue of pandoras battery) my brother cracked his lcd screen and the whole right side doesnt work. Instead of buying a new psp he is waiting for the psp slim. so i just want to try the pandora battery method myself by bricking his psp then recovering it. I also want to see if the psp can recover from a 100% corrupt or missing flash. if you feel its not a good idea to post the function on the forum, please pm me it


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