R
Ron Eggler
Hi,
I have a struct array in my application. I want to call a function, change
values of struct variables and return back to main - while still keeping
the information written in the function.
I thought I'd do it as pasted below but my problem is that my thread
terminates whenever i access SumStruct_ptr's elements to read/write values
and i have no clue why, could anyone help please?
Thanks alot!
I have a struct array in my application. I want to call a function, change
values of struct variables and return back to main - while still keeping
the information written in the function.
I thought I'd do it as pasted below but my problem is that my thread
terminates whenever i access SumStruct_ptr's elements to read/write values
and i have no clue why, could anyone help please?
Thanks alot!
Code:
typedef struct {
char * BusID;
int SeqNr;
unsigned short Msg;
} MsgStruct;
int StructCount=0;
int CheckStruct (MsgStruct **SumStruct_ptr, io_t *CurrentBus)
{
prs_log(LOG_CRIT,"***in CheckStruct, sizeof(%d), StructCount:%d",
sizeof(SumStruct_ptr), StructCount);
int i=0;
if (StructCount==0){
prs_log(LOG_CRIT,"***in if, StructCount: %d,", StructCount);
(*SumStruct_ptr) = calloc( StructCount + 1, sizeof( MsgStruct ) );
prs_log(LOG_CRIT,"***sucessfully allocated space: %d",
sizeof((*SumStruct_ptr)));
(*SumStruct_ptr)[StructCount].BusID=CurrentBus->id;
(*SumStruct_ptr)[StructCount].SeqNr=CurrentBus->seq;
(*SumStruct_ptr)[StructCount].Msg=0x00;
StructCount++;
prs_log(LOG_CRIT,"***Values in SumStruct_ptr[%d]: BusID:%s seqNr:%d
Msg:0x%x", StructCount, (*SumStruct_ptr)[StructCount].BusID,
(*SumStruct_ptr)[StructCount].SeqNr, (*SumStruct_ptr)[StructCount]);
}
// some more code to extend the array
}
main(void)
{
static MsgStruct *SumStruct;
Pos = CheckStruct(&SumStruct,_cur_io);
SumStruct[Pos].Msg|=TSP_SERVICE_REQUEST;
}