The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

How Java can do C/C++ union?

Posted by Philip Chang on June 15, 2001 at 12:18 PM

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);
}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us