Some help with typedef and pointers.
Posted: Wed Mar 20, 2013 3:07 pm
I have always had trouble with pointers. Would someone please help me to understand how to print out the value of Head1.
This chunk of example code came from a vender. So no need to ask why i am doing this or that
This chunk of example code came from a vender. So no need to ask why i am doing this or that
Code: Select all
#define COMMAND_START_CODE1 0x55
#define COMMAND_START_CODE2 0xAA
typedef struct {
unsigned char Head1;
unsigned char Head2;
unsigned char wDevId0;
unsigned char wDevId1;
unsigned char nParam0;
unsigned char nParam1;
unsigned char nParam2;
unsigned char nParam3;
unsigned char wCmd0;// or nAck
unsigned char wCmd1;
unsigned char wChkSum0;
unsigned char wChkSum1;
} SB_OEM_PKT;
SB_OEM_PKT* Command_Packet;
/*********Change Baudrate Command***********/
Command_Packet->Head1 = COMMAND_START_CODE1;
Command_Packet->Head2 = COMMAND_START_CODE2;
Command_Packet->wDevId0 = DEVICE_ID;
Command_Packet->wDevId1 = DEVICE_ID>>8;
Command_Packet->nParam0 = State & 0xFF;
Command_Packet->nParam1 = (State & 0xFF00) >> 8 ;
Command_Packet->nParam2 = (State & 0xFF0000) >> 16;
Command_Packet->nParam3 = (State & 0xFF000000) >> 24;
Command_Packet->wCmd0 = CMOSLED;
Command_Packet->wCmd1 = ZERO;
tmp = CalcChkSumOfCmdAckPkt(Command_Packet);
Command_Packet->wChkSum0 = tmp % 256;
Command_Packet->wChkSum1 = tmp >> 8;
/*********Change Baudrate Command***********/
// the result is 0, and i do not know why.
iprintf("%x", (unsigned char*)Command_Packet->Head1);