Re: Java to C Structure Communication

Jeff Kesselman <[email protected]> Thu, 7 Feb 2008 11:27:19 -0500
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Mann, Ivan H wrote:
> This URL has code sketched out for using Java to send C data structures
> to legacy C transaction based systems.  I wrote a program based on this
> and it works quite well.
>
>
>> http://forum.java.sun.com/thread.jspa?messageID=3162834&tstart=0
>>
>>
>>
>         There is a design point left out of this, however.  It shows how
> to send and receive fixed length character fields, 32 bit integer
> fields, 64  bit integer fields, etc.  The C data type missing is
> unsigned int and/or unsigned long.
>
>         Would anybody have an idea how to send and receive a 32 bit
> integer field in which the top bit does not indicate a negative number?
>
Java int is an unsigned 32 bit number.  That being said, you need to
match endianess.  Java uses
network format.  C uses processor format and is thus system dependent.

So there IS no general answer, it depends on the processor your C code
is running on.

Btw, I would NOT use DataInputStream unless you are stuck on a legacy
Java versiuon.

User ByteBuffer and it will handle endianess for you as long as you set
it right.

JK

=======================================================================
Journalism 101: The difference between news and a press release

News tells you what the reporter thinks is true.

A press release tells you what a company wants *you* to think is true.

Only bad reporters think the two are the same.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com