How JAVA can do C/C++ union?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Philip_Chang
Posted On:   Friday, June 15, 2001 08:37 AM

I would like to know the best way to map a 100-byte array to class instance variables: byte [] myArray = { '1', '2', '3', ..... }; // 100 bytes class BlockOf100Bytes { byte field1[4]; byte field2[26]; byte field3[41]; byte field4[9]; byte field5[20]; public void mapIt( byte [] byteArray ) { // how to map byteArray to field1 to field5? ...java code...? // C++ can do the following: BlockOf100Bytes *pBlock = (BlockOf100Bytes *)byteArray; printf("field3=%.41s", pBlock->field3); } }    More>>

I would like to know the best way to map a 100-byte array to class instance variables:



byte [] myArray = { '1', '2', '3', ..... }; // 100 bytes



class BlockOf100Bytes {

byte field1[4];

byte field2[26];

byte field3[41];

byte field4[9];

byte field5[20];



public void mapIt( byte [] byteArray )

{

// how to map byteArray to field1 to field5?

...java code...?



// C++ can do the following:

BlockOf100Bytes *pBlock =

(BlockOf100Bytes *)byteArray;



printf("field3=%.41s", pBlock->field3);

}

}

   <<Less

Re: How JAVA can do C/C++ union?

Posted By:   John_Mitchell  
Posted On:   Sunday, June 17, 2001 02:28 PM

Java doesn't support unions. You'll have to transform the bytes and appropriately assign those values to the fields in an object.
About | Sitemap | Contact