A problem with structures and pointers ...

Q

Quantum

I have the following Code I have a problem with.
DataValues and RegNbr etc ... Never get written to.
There's a problem about accessing the data structure member sdata.
Can Any body Help ...

Reply to (e-mail address removed)

A C programmer ...
typedef struct
{
Uint32 lwDataSize;
Uint16 BoxIdOpFrom; /*The owner of the op*/
Uint16 BoxIdOpTo; /*The destinataire op*/
Uint16 wOpCode;
Uint8 *sData;
}CommStructData;

RetCode OperationSetRegister(CommStructData *pStructDataIn)
{
Uint8 *DataValues;
Uint8 RegNbr;
Uint8 RegValue;
RetCode err=ERR_OK;

DataValues = (Uint8 *) pStructDataIn->sData;
RegNbr = *DataValues;
DataValues++;
RegValue = *DataValues;

Rs232RFWriteReg(RegNbr, RegValue);
err = SendRegister(RegNbr, RegValue);

}
 
D

David Resnick

Quantum said:
I have the following Code I have a problem with.
DataValues and RegNbr etc ... Never get written to.
There's a problem about accessing the data structure member sdata.
Can Any body Help ...

Reply to (e-mail address removed)

A C programmer ...
typedef struct
{
Uint32 lwDataSize;
Uint16 BoxIdOpFrom; /*The owner of the op*/
Uint16 BoxIdOpTo; /*The destinataire op*/
Uint16 wOpCode;
Uint8 *sData;
}CommStructData;

RetCode OperationSetRegister(CommStructData *pStructDataIn)
{
Uint8 *DataValues;
Uint8 RegNbr;
Uint8 RegValue;
RetCode err=ERR_OK;

DataValues = (Uint8 *) pStructDataIn->sData;
RegNbr = *DataValues;
DataValues++;
RegValue = *DataValues;

Rs232RFWriteReg(RegNbr, RegValue);
err = SendRegister(RegNbr, RegValue);

}

You don't give the full context. Where exactly is
sData allocated? You are treating it as an array of
at least two pointers to Uint8, which hold the "RegNbr" and
"RegValue" respectively. Do you somewhere malloc this array,
as in foo->sData = malloc(ARRAY_ELTS * sizeof *foo->sData)?

I'd get rid of the DataValues and its increment, and say that
RegNbr = pStructDataIn->sData[0];
RegValue = pStructDataIn->sData[1];
But whatever, that is a matter of taste.

The (Uint8 *) cast also looks dodgy, why are you casting
something to the type it already is?

-David
 
Q

Quantum

accessing the sData member like this did solve the problem ....

RegNbr = pStructDataIn->sData[0];
RegValue = pStructDataIn->sData[1];

A C programmer ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top