Array problem

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

Moderators: cheriff, TyRaNiD

Post Reply
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Array problem

Post by jojojoris »

I have some strange problems.

Code: Select all

game::game() {
    notenames[1] = "A";
    notenames[2] = "A#";
    notenames[3] = "B";
    notenames[4] = "C";
    notenames[5] = "C#";
    notenames[6] = "D";
    notenames[7] = "D#";
    notenames[8] = "E";
    notenames[9] = "F";
    notenames[10] = "F#";
    notenames[11] = "G";
    notenames[12] = "G#";
    running = true;
}

bool game::run() {    
    while (running) {        
        pspDebugScreenSetXY(0,0);
        pspDebugScreenPrintf("-%s-",notenames[2]);
        for&#40;short i=0;i<5;i++&#41;sceDisplayWaitVblankStart&#40;&#41;;
    &#125;
    return true;
&#125;
and in the main:

Code: Select all

game GG;
GG.run&#40;&#41;;
The output has strange behaviour.
The output is:

Code: Select all

-&#40;null&#41;-
And the background had a b=green/blue collor. I always tought that the background collor should be black by default.

Now my question:
What did i do wrong?
I want the output:

Code: Select all

-A#-
Last edited by jojojoris on Mon Apr 27, 2009 4:22 am, edited 1 time in total.

Code: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

what is the type of notename ? String ?
where is the new of the class game?
before your constructor has been called is must been instancied by a new no ?
Last edited by sauron_le_noir on Mon Apr 27, 2009 4:21 am, edited 1 time in total.
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

sauron_le_noir wrote:what is the type of notename ? String ?
where is the new of the class GG ?
before your constructor has been called is must been instancied by a new no ?
ooo

Sorry i forget to tell

its a char *

lets say notenames is an array of (char *)

Code: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

why not using string in your c++ program string type is a object type
char * are pointer used just for compatibility with C

to use your string on operating function like the DebugPrintf just use the c_str() function provide by C++.

With string the compiler can at compile time perform a lot of checks.
on pointer ... it's at runtime and you can have lot of memory leaks ;)

At this site you've got a tuto to write a c++ program on psp

http://www.ghoti.nl/PSPtutorial2.php
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

When i use the string type my program crashes and it when i use psp-addr2line is said:

Code: Select all

C&#58;\projects\PSPGuitarHelper>psp-addr2line -e pspgg.elf 0x00002EA0
x&#58;/workspace/minpspw/psp/build/gcc-4.3.3/psp/libstdc++-v3/include/bits/basic_string.h&#58;316
I found out that when i use memset it all works well.

Code: Select all

game&#58;&#58;game&#40;&#41; &#123;
    memset&#40;notenames,0,18&#41;;
    notenames&#91;1&#93; = &#40;char*&#41;"A";
    notenames&#91;2&#93; = &#40;char*&#41;"A#";
    notenames&#91;3&#93; = &#40;char*&#41;"B";
    notenames&#91;4&#93; = &#40;char*&#41;"C";
    notenames&#91;5&#93; = &#40;char*&#41;"C#";
    notenames&#91;6&#93; = &#40;char*&#41;"D";
    notenames&#91;7&#93; = &#40;char*&#41;"D#";
    notenames&#91;8&#93; = &#40;char*&#41;"E";
    notenames&#91;9&#93; = &#40;char*&#41;"F";
    notenames&#91;10&#93; = &#40;char*&#41;"F#";
    notenames&#91;11&#93; = &#40;char*&#41;"G";
    notenames&#91;12&#93; = &#40;char*&#41;"G#";
    running = true;
&#125;
Your site looks usefull. I''m new at object orientating proramming.

Code: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

variable not initialized = memory leak = fatal error
for the string it is strange i have no problem with it i use list,arrary etc ...
do you have the last toolchain ? and the last gcc ?

Are you compiling under windows -> if yes using the heimdall implementation
of the cygwin one if under linux witch gcc has compile the cross compiler
psp-gcc , is the version of psp-gcc (GCC) -->4.3.2
Post Reply