This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can pointer types be cast?

Here is my problem, i have several simmilar structue definitions (containers for messages)

struct FIRST{
unsigned char Word_Pos[8]
unsigned char Data[8]
unsigned char Msg_Len
};
struct FIRST A

struct SECOND{
unsigned char Word_Pos[4]
unsigned char Data[4]
unsigned char Msg_Len
};
struct SECOND B

struct THIRD{
unsigned char Word_Pos[10]
unsigned char Data[10]
unsigned char Msg_Len
};
struct THIRD C

Is there a way to declare single pointer (lets say "P") such that i will be able to point to each of these structures so i can transparently use:
P->Word_Pos []
P->Data []
P->MSG_Len in my ISR.

I realise i could just declare 3 structures of type THIRD and just use one pointer easily, but in my actual application there will be many of these simmilar but different structures and i am trying to save ram.

Parents
  • You are absolutely right. I will most likely create a union of type unsigned char[] and my structure.

    BTW not that it makes much difference but Data was supposed to be an unsigned int not char.
    I wish it was as easy as a sequential buffer read though.
    When transmitted each word needs to be byte swapped. There can be up to 100 two byte words however we will never modifying more than 8 words in any message. All unmodified words need a 0x00 transmitted as a placeholder

    I guess now the uses of Word_Pos becoms more apparent...

Reply
  • You are absolutely right. I will most likely create a union of type unsigned char[] and my structure.

    BTW not that it makes much difference but Data was supposed to be an unsigned int not char.
    I wish it was as easy as a sequential buffer read though.
    When transmitted each word needs to be byte swapped. There can be up to 100 two byte words however we will never modifying more than 8 words in any message. All unmodified words need a 0x00 transmitted as a placeholder

    I guess now the uses of Word_Pos becoms more apparent...

Children
No data