• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Data Structure

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic