Converting a structs to a unsigned short-pointer ??

Post Reply
DarkShadow44
Posts: 19
Joined: Wed Apr 15, 2009 3:17 pm

Converting a structs to a unsigned short-pointer ??

Post by DarkShadow44 » Mon May 11, 2009 6:30 pm

Hello!
Is it possible to convert a struct to a pointer like this:

Code: Select all

typedef struct
{
     int value_1;
     int value_2;
}test_struct;

test_struct test;

int main()
{
     test_struct* pointer = &test;

     unsigned short* shortPtr=(unsigned short*) pointer;
}
I want to use it for wifi:

Code: Select all

Wifi_RawTxFrame(sizeof(test_struct)+1, 0x0014, shortPtr) ;
Afer sending the clients must decode it like

Code: Select all

void Handler(int packetID, int readlength) 
{ 
     test_struct test2; 
     static int bytesRead; 

     bytesRead = Wifi_RxRawReadPacket(packetID, readlength, (unsigned short*)test2); 
}

Please Help!!!

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: Converting a structs to a unsigned short-pointer ??

Post by Sylus101 » Mon May 11, 2009 9:49 pm

I'm not 100% sure, but I believe you should be able to just cast directly in the function without the need to create shortPtr (same as you did in the Handler function):

Code: Select all

Wifi_RawTxFrame(sizeof(test_struct)+1, 0x0014, (unsigned short*)pointer);
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Al_Bro
Posts: 15
Joined: Wed Apr 08, 2009 10:33 pm

Re: Converting a structs to a unsigned short-pointer ??

Post by Al_Bro » Tue May 12, 2009 8:34 pm

Never used those functions myself, but you'd probably need to change the line to something like:

Code: Select all

bytesRead = Wifi_RxRawReadPacket(packetID, readlength, (unsigned short*)&test2);
(i.e. take the reference to variable test2).

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests