Re: Java to C Structure Communication

Patrick Schneider <[email protected]> Thu, 7 Feb 2008 11:46:58 -0600
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
I was under the impression that Java integral types are signed
two's-complement integers...

What did you mean by this:

> Java int is an unsigned 32 bit number.

? ... or am I missing something?

On Feb 7, 2008 10:27 AM, Jeff Kesselman <[email protected]> wrote:

> 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(R)  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

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

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