|
|
initialize arrays in structs.
#312135
02/23/10 13:27
02/23/10 13:27
|
Joined: Jan 2007
Posts: 2,247 Deutsch Niedersachsen
Puppeteer
OP
Expert
|
OP
Expert
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
|
How can i initialize a struct like this:
typedef struct
{
var test[3];
}teststruct;
This doesnt work
teststruct* bla=
{
test[0]=1; test[1]=2; test[2]=1;
}
Neither this:
teststruct* bla=
{
test={1,2,3};
}
whats the right way to do it?
Last edited by Puppeteer; 02/23/10 13:28.
|
|
|
Re: initialize arrays in structs.
[Re: Puppeteer]
#312137
02/23/10 13:33
02/23/10 13:33
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
typedef struct
{
var test[3];
}teststruct;
teststruct* bla() {
teststruct* tempStruct = sys_malloc( sizeof(teststruct) );
var i;
for(i=0; i<3; i++) {
tempStruct.test[i] = 0;
}
return(teststruct);
}
I have it like that, should work. regards,
Last edited by Helghast; 02/23/10 13:36. Reason: sys_malloc, not sys_nxalloc for this :)
|
|
|
Re: initialize arrays in structs.
[Re: Helghast]
#312140
02/23/10 13:39
02/23/10 13:39
|
Joined: Jan 2007
Posts: 2,247 Deutsch Niedersachsen
Puppeteer
OP
Expert
|
OP
Expert
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
|
Hm but this is a function. I'd like to initilize it while compiling. So i can create some data in the scripts (i will use it for some animation stuff like this:
MM_MOVE_MODE* cbabe_walk_state=
{
moves[1]=walk_forwardrrr;
moves[2]=walk_forwardrr;
moves[3]=walk_forwardr;
moves[4]=walk_forward;
moves[5]=walk_forwardl;
moves[6]=walk_forwardll;
moves[7]=walk_forwardlll;
moves[8]=NULL;
moves[9]=NULL;
moves[10]=NULL;
moves[11]=NULL;
moves[12]=NULL;
moves[13]=NULL;
moves[14]=NULL;
moves[15]=NULL;
num_moves=8;
}
and i dont want to initialize it at runtime since things would get reeeeeaaally messy then.
|
|
|
|
|
|