GP32 I Don't Know How To Describe This Question


Hooka

That Guy!
Joined
Jul 19, 2003
Messages
1,746
Age
41
Location
Canada
Website
Visit site
Ok, I'm getting this error:

error: variable-size type declared outside of any function

And I'm pretty sure it's because I changed a #define into an int because I need it to change at runtime, only problem is that it's used as an array subscript outside of a function (atleast I think that's what I think this is, the #define changed to an int is NUMSNDCHUNKS)

extern byte *audiosegs[NUMSNDCHUNKS];

Now could I do something like:

#define NUMSNDCHUNKS
#define WL6_NUMSNDCHUNKS 288
#define SOD_NUMSNDCHUNKS 267

void blabla(){
if (wolftype == WOLF){
NUMSNDCHUNKS = WL6_NUMSNDCHUNKS;
}else{
NUMSNDCHUNKS = SOD_NUMSNDCHUNKS;
}
}

Or is there anyway to do this?

I'll give it a couple tries when I get home but I just though I'd ask and see if anybody thought this was a sane way....

Edit: thanks pea, I had thought of that first but then I wondered if it would still complain about the int. I'll give this a try and see where I stand after that :)


Unfortunately that doesn't seem to be an option (gives the same error) I've gotten rid of most of the errors so far (used a sneaky yet horrible way to do it though) but I've got one left and have no clue how I'm giong to get around it :S So close yet so far, time to sit here and think I guess...
 
um. isn't #define used only at compile time, and never at runtime? You need to declare an actual variable?

Code:
#define WL6_NUMSNDCHUNKS 288
#define SOD_NUMSNDCHUNKS 267

static int NUMSNDCHUNKS;

void blabla(){
if (wolftype == WOLF){
NUMSNDCHUNKS = WL6_NUMSNDCHUNKS;
}else{
NUMSNDCHUNKS = SOD_NUMSNDCHUNKS;
}
}


I think what would happen in your first example is that your #defines would be substituted at compile time to give the following code, which is obviously crazy:
Code:
#define NUMSNDCHUNKS  // Same as #define NUMSNDCHUNKS 1
#define WL6_NUMSNDCHUNKS 288
#define SOD_NUMSNDCHUNKS 267

void blabla(){
if (wolftype == WOLF){
1 = 288;
}else{
1 = 267;
}
}
 
can you just reference the extern array as a pointer to the first byte pointer, then make sure you only access the elements that are relevant?

e.g.


extern byte **audiosegs;

void blabla(){
if (wolftype == WOLF){
numsndchunks = WL6_NUMSNDCHUNKS;
}else{
numsndchunks = SOD_NUMSNDCHUNKS;
}

then only access the first numsndchunks of the array.

not sure if that works never tried it but worth having a go..

sam
 
actually for now I've just moved the line of code into any function that used it (about 5 of them) gets rid of the error but I have to get rid of a similar error (same type just different chunk of code) to figure out if I totally butchered it or if it will work... but I've started implementing my idea so only time will tell ;)
 
I somehow have the feeling what you're coding now is (very) ugly..
:p
 
Back
Top