Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Structure

 
Isaias C. Barroso
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to transfer the follow Data Structure for to a Socket with Java.
Structure in C
typedef struct data_outboundrec
{
unsigned long intcnumber;
unsigned chardevice_id[20];
unsigned char data[255];
unsigned intdatasize;
} DATAOUTBOUND_REC;
how to make this.
Thanks
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't say. In C, both the endian-ness and the size of the data types is machine-dependent and even compiler-dependent. But you probably know what hardware platform this is going to run on; if you're lucky, its endian-ness corresponds exactly to that used by java.io.DataOutputStream.In that case the above code might come close to working. I assumed that "datasize" is the size of the data in the data field -- although using an int for this would be a bit weird. I also assumed that your C compiler thinks that a long is 64 bit, an int 32 bit and a char 8 bit. Mind that Java doesn't have unsigned data types (apart from char); that may give you some grief, although usually you can get away with doing your calculations using the next larger data type (e.g. int -- 32 bits) and casting to the signed type of the right size (e.g. short -- 16 bits) at the last moment.
- Peter
[ June 10, 2003: Message edited by: Peter den Haan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic