Have you done work with pointers and know how they work?
Printable View
Have you done work with pointers and know how they work?
This is my first time working with them.Zitat:
Zitat von yaustar
And I understand how they work, just not compleatly enough to notice bugs...yet.
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?
'Found' the bug. That code is outside function scope. Eg
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.Code:Image * img;
img->width = 100;
//etc
int main()
{
}
-= Double Post =-
No you don't otherwise you would have noticed why it would crash immediately.Zitat:
Zitat von MrChaos
I understand that. I was just throwing it out there.Zitat:
Zitat von Archaemic
Zitat:
Zitat von JustChris
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.
I said I didn't understand them "compleatly" :P.Zitat:
Zitat von yaustar
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:
Yeah, that's where it is. What SHOULD be in the logo data, instead of what I have?Code:
logo->data = 0x7fff,0x7fff,0x7fff,0x7fff, // and so on...;
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.
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.Zitat:
Zitat von JustChris
++ B.
*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.Zitat:
Zitat von PSPJunkie_
But...Now my compiler "can't convert short unsigned int [127840]' to Color* in assignment".
I think the compiler hates me too.
In that case, you can't. You can't initialise arrays in the initialisation list of a construct.Zitat:
Zitat von JustChris
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.
Maybe try masking it? I honestly don't know if that will do anything, though.
An error is only useful if we see the code that refers to the error.Zitat:
Zitat von MrChaos
It's:Zitat:
Zitat von yaustar
logo->data = imageData;
But it referrs to the .c img file that bin2c made...
The first one is the only one with an assignment.
What is the datatype of logo->data and imageData?Zitat:
Zitat von MrChaos
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...Zitat:
Zitat von yaustar
Declaration of the datatype of logo = Image* logo
Declaration of the datatype of imageData = unsigned short imageData
'data' is a u32, and imageData is an unsigned char.
Geez, look at the previous page. Logo is an Image*
E] Make that two pages ago
Ok. I learn stuff every day. Thanks. :tup:Zitat:
Zitat von PSPJunkie_
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).
Basically, the data NEEDs to be in 32 bit format for this to work with graphics.h.Code:unsigned short imageData
// Change to
unsigned int imageData
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.
Um, try looking at graphics.h or the file that bin2c created.
andCode:typedef u32 Color;
Code:static unsigned char hw[] __attribute__((aligned(16)));
Ok. If I include it in the makefile, will it still show in the folder?Zitat:
Zitat von yaustar
I don't have either at hand hance I asked for them.Zitat:
Zitat von PSPJunkie_
A short is 2 bytes.Zitat:
Zitat von MrChaos
I don't use bin2c (even though I said I did; I use graphicsto16bitc)Zitat:
Zitat von PSPJunkie_
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.Zitat:
Zitat von Archaemic
Chaos, save the image as a .raw, then bin2c it.
I never said anything about its members.
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.Zitat:
Zitat von PSPJunkie_
Zitat:
Zitat von yaustar
No worries, I was referring to MrChaos.
I did by asking for the struct declaration. This information was not 2 pages back.Zitat:
Zitat von Archaemic
It's part of the PSPSDK.Zitat:
Zitat von MrChaos
It is in the bin folder of the compiler.Zitat:
Zitat von MrChaos
Oh, ok. Got it.Zitat:
Zitat von PSPJunkie_
EDIT: Ugh. Won't run. Screw it guys, I'll just make it open up the image file, but ty for all your help.
But I'll ask the second time, if I include a pic in the makefile, will it still need to be in the folder after I compile?
Yeah, but you also asked what type logo was, and that information WAS. That's all I'm saying.Zitat:
Zitat von yaustar
MrChaos: Yes
Ok, thanks.Zitat:
Zitat von Archaemic
Open up terminal. Type,
You need to be in to directory of the image, not bin2c. So you could do,Zitat:
Zitat von bin2c
and you would refer to the image as 'logo' in your sources.Zitat:
bin2c logo.raw logo.h logo
Point.Zitat:
Zitat von Archaemic
Ah. Ok. When I try this tomorrow, where does the *.raw have to be at?Zitat:
Zitat von PSPJunkie_