File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Data Structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Data Structure" Watch "Data Structure" New topic

Data Structure

Isaias C. Barroso
Ranch Hand

Joined: Jan 22, 2002
Posts: 165
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;
how to make this.

Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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 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 ]
I agree. Here's the link:
subject: Data Structure
It's not a secret anymore!