Seite 153 von 340 ErsteErste ... 53 103 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 203 253 ... LetzteLetzte
Zeige Ergebnis 4.561 bis 4.590 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; Have you done work with pointers and know how they work?...

  
  1. #4561
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Have you done work with pointers and know how they work?



  2. #4562
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    Have you done work with pointers and know how they work?
    This is my first time working with them.
    And I understand how they work, just not compleatly enough to notice bugs...yet.

  3. #4563
    Developer
    Points: 5.085, Level: 45
    Level completed: 68%, Points required for next Level: 65
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    206
    Points
    5.085
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    How do you initialize an array SEPARATELY from its declaration? I want all elements to be intialized in one statement, not going through the indices one by one. Is there another way besides using a typedef struct?
    GameSnooper - Random drawing of gaming news

    The 32 Bit Shell - My development blog (also includes gaming oddities)

  4. #4564
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    'Found' the bug. That code is outside function scope. Eg
    Code:
    Image * img;
    img->width = 100;
    //etc
    int main()
    {
    
    }
    This is illegal syntax. You can create and declare, define and initialise variables outside function scope but you can't do anything more with them outside function scope.
    -= Double Post =-
    Zitat Zitat von MrChaos
    This is my first time working with them.
    And I understand how they work, just not compleatly enough to notice bugs...yet.
    No you don't otherwise you would have noticed why it would crash immediately.
    Geändert von yaustar (05-19-2007 um 04:59 PM Uhr) Grund: Automerged Doublepost

  5. #4565
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Archaemic
    That wouldn't fix it. That's definitely a pointer to an object, and not an object in and of itself. Hence you'd use ->
    I understand that. I was just throwing it out there.

  6. #4566
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von JustChris
    How do you initialize an array SEPARATELY from its declaration? I want all elements to be intialized in one statement, not going through the indices one by one. Is there another way besides using a typedef struct?
    Code:
    int anArray1[4] = { 0 }; // All values in the array are 0
    int anArray2[4] = { 1, 2, 4, 6 }; // The array has been given the values 1, 2, 4 and 6
    int anArray3[4] = { 1, 2 }; // Illegal. You cannot partially initialise an array.

  7. #4567
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    'Found' the bug. That code is outside function scope. Eg
    Code:
    Image * img;
    img->width = 100;
    //etc
    int main()
    {
    
    }
    This is illegal syntax. You can create and declare, define and initialise variables outside function scope but you can't do anything more with them outside function scope.
    -= Double Post =-

    No you don't otherwise you would have noticed why it would crash immediately.
    I said I didn't understand them "compleatly" :P.

    Ok, I fixed the 'bug'. But I need to fix something else. When I fixed it, then compiled, the compiler spit out 637 errors, saying that the image data is incorrect. I'm back to my first problem now. My logo data is this:

    Code:
     
    logo->data = 0x7fff,0x7fff,0x7fff,0x7fff, // and so on...;
    Yeah, that's where it is. What SHOULD be in the logo data, instead of what I have?

  8. #4568
    Developer
    Points: 5.085, Level: 45
    Level completed: 68%, Points required for next Level: 65
    Overall activity: 0%

    Registriert seit
    Oct 2005
    Beiträge
    206
    Points
    5.085
    Level
    45
    Downloads
    0
    Uploads
    0

    Standard

    Yaustar, that works in normal cases, but I guess I need to mention now that the array I'm trying to use is declared as a private member of a class. I can't initialize it in the class declaration. Ideally it needs to be initialized in one method, and other methods called after it would be able to use the array.
    GameSnooper - Random drawing of gaming news

    The 32 Bit Shell - My development blog (also includes gaming oddities)

  9. #4569
    QJ Gamer Green
    Points: 5.784, Level: 49
    Level completed: 17%, Points required for next Level: 166
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Ort
    France
    Beiträge
    753
    Points
    5.784
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von JustChris
    How do you initialize an array SEPARATELY from its declaration? I want all elements to be intialized in one statement, not going through the indices one by one. Is there another way besides using a typedef struct?
    See what yaustar said, but his only works at the declaration moment, later in your code, you can't us eit anymore, you'll have to go to each indices.

    ++ B.
    if I make mistakes in english, feel free to correct me or else i won't progress :D .

  10. #4570
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    *Goes into a coma from banging had against wall"

    bin2c spits a .c file out with the data definition already.

    Do,
    Code:
    img->data = variable_from_bin2c;

  11. #4571
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPJunkie_
    *Goes into a coma from banging had against wall"

    bin2c spits a .c file out with the data definition already.

    Do,
    Code:
    img->data = variable_from_bin2c;
    LOL! By this point you guys hate me now. Sorry guys, I studied C++, but apperently, haven't learned enough. But, I like to learn from expericence.

    But...Now my compiler "can't convert short unsigned int [127840]' to Color* in assignment".

    I think the compiler hates me too.

  12. #4572
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von JustChris
    Yaustar, that works in normal cases, but I guess I need to mention now that the array I'm trying to use is declared as a private member of a class. I can't initialize it in the class declaration. Ideally it needs to be initialized in one method, and other methods called after it would be able to use the array.
    In that case, you can't. You can't initialise arrays in the initialisation list of a construct.

    If you are using C++ then you really should be using vectors instead of arrays otherwise your only other option is to use a for loop.

  13. #4573
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Maybe try masking it? I honestly don't know if that will do anything, though.

  14. #4574
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von MrChaos
    LOL! By this point you guys hate me now. Sorry guys, I studied C++, but apperently, haven't learned enough. But, I like to learn from expericence.

    But...Now my compiler "can't convert short unsigned int [127840]' to Color* in assignment".

    I think the compiler hates me too.
    An error is only useful if we see the code that refers to the error.

  15. #4575
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    An error is only useful if we see the code that refers to the error.
    It's:

    logo->data = imageData;

    But it referrs to the .c img file that bin2c made...

  16. #4576
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    The first one is the only one with an assignment.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  17. #4577
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von MrChaos
    It's:

    logo->data = imageData;

    But it referrs to the .c img file that bin2c made...
    What is the datatype of logo->data and imageData?
    What is the datatype of logo?
    What is the declaration of the datatype of logo?
    What is the declaration of the datatype of imageData?

  18. #4578
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    What is the datatype of logo->data and imageData?
    What is the datatype of logo?
    What is the declaration of the datatype of logo?
    What is the declaration of the datatype of imageData?
    Datatype of logo = Not sure what you mean by that...
    Declaration of the datatype of logo = Image* logo
    Declaration of the datatype of imageData = unsigned short imageData

  19. #4579
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    'data' is a u32, and imageData is an unsigned char.

  20. #4580
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Geez, look at the previous page. Logo is an Image*
    E] Make that two pages ago
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  21. #4581
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPJunkie_
    'data' is a u32, and imageData is an unsigned char.
    Ok. I learn stuff every day. Thanks.

  22. #4582
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    This is going to be problematic. Image->data is a Color * which is a typedef'ed u32 which is an unsigned int (32 bit). imageData however is an array of unsigned shorts which are 16 bit.

    If you change the following code, it will compile but won't give you the correct results (ignoring the fact that the program will still crash).
    Code:
    unsigned short imageData
    // Change to
    unsigned int imageData
    Basically, the data NEEDs to be in 32 bit format for this to work with graphics.h.

    To make this painless, just load the image from a seperate image file rather then try to compile the data with the code. It isn't worth the hassle.

  23. #4583
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Um, try looking at graphics.h or the file that bin2c created.

    Code:
    typedef u32 Color;
    and

    Code:
    static unsigned char hw[] __attribute__((aligned(16)));

  24. #4584
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von yaustar
    This is going to be problematic. Image->data is a Color * which is a typedef'ed u32 which is an unsigned int (32 bit). imageData however is an array of unsigned shorts which are 16 bit.

    If you change the following code, it will compile but won't give you the correct results (ignoring the fact that the program will still crash).
    Code:
    unsigned short imageData
    // Change to
    unsigned int imageData
    Basically, the data NEEDs to be in 32 bit format for this to work with graphics.h.

    To make this painless, just load the image from a seperate image file rather then try to compile the data with the code. It isn't worth the hassle.
    Ok. If I include it in the makefile, will it still show in the folder?

  25. #4585
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPJunkie_
    Um, try looking at graphics.h or the file that bin2c created.

    Code:
    typedef u32 Color;
    and

    Code:
    static unsigned char hw[] __attribute__((aligned(16)));
    I don't have either at hand hance I asked for them.

    Zitat Zitat von MrChaos
    Datatype of logo = Not sure what you mean by that...
    Declaration of the datatype of logo = Image* logo
    Declaration of the datatype of imageData = unsigned short imageData
    A short is 2 bytes.

  26. #4586
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPJunkie_
    Um, try looking at graphics.h or the file that bin2c created.

    Code:
    typedef u32 Color;
    and

    Code:
    static unsigned char hw[] __attribute__((aligned(16)));
    I don't use bin2c (even though I said I did; I use graphicsto16bitc)

  27. #4587
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Archaemic
    Geez, look at the previous page. Logo is an Image*
    E] Make that two pages ago
    Saying it is an Image tells me nothing of the datatypes of the members hence I asked for a declaration since it is a non-standard datatype.

  28. #4588
    QJ Gamer Green
    Points: 11.300, Level: 70
    Level completed: 13%, Points required for next Level: 350
    Overall activity: 0%

    Registriert seit
    Dec 2006
    Ort
    main();
    Beiträge
    1.071
    Points
    11.300
    Level
    70
    Downloads
    0
    Uploads
    0

    Standard

    Chaos, save the image as a .raw, then bin2c it.

  29. #4589
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    I never said anything about its members.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  30. #4590
    QJ Gamer Blue
    Points: 4.031, Level: 40
    Level completed: 41%, Points required for next Level: 119
    Overall activity: 91,0%

    Registriert seit
    Feb 2007
    Ort
    Florida
    Beiträge
    214
    Points
    4.031
    Level
    40
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von PSPJunkie_
    Chaos, save the image as a .raw, then bin2c it.
    Can you do me a favor, and send me a link to bin2c? All I find is the one I have right now, and that aint it.


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:15 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .