BYTE *data = (BYTE *)&gPacket; // converts to pointer to BYTE for (int a = 0; a < sizeof(PACKET); a++) // cycles through bytes { SCI_PrintByte(data[a]); } -Kieren ----- Original Message ----- From: "Donovan Parks" To: Sent: Sunday, August 11, 2002 7:09 AM Subject: [PIC]: Hi-Tech C / C Question: Accessing Bytes in a struct > Hello, > > I'm hoping there is a Hi-Tech C / C guru here that can give me a hand. What > I have is the following struct: > > struct PACKET // structure to hold incomming packets > { > BYTE packetLen; > BYTE msgType; > BYTE msgContents[MAX_CONTENTS_SIZE]; > BYTE checksum; > } gPacket={0, 0, {0}, 0}; > > Now, what I would like to do is print off each byte in this struct without > having to access them using the "." operator. > > I can obviously do this: > SCI_PrintByte(gPacket.packetLen); > SCI_PrintByte(gPacket.msgType); > ... > ... > > But, what I am hoping for is something like: > for(i = 0; i < 6; i++) > SCI_PrintByte(*(&gPacket+i)); // this does not work! -> is there > something that will? > > > &gPacket should give me the address of the gPacket structure and the "*" > operator should then given me the value at that address. I receive a > compiler error indicating I am going an "illegal conversion". Anyone? > Thanks. > > Regards, > Donovan Parks > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics