Tool for sharing C data-structures with Java

Discussion in 'Java' started by Rick Giuly, Nov 13, 2004.

  1. Rick Giuly

    Rick Giuly Guest

    I'm thinking about making a program in java that will allow you to use
    C data-structures (probably read from a network) easily:

    My question: has anyone already done this?

    here's the approach that I'm thinking of:

    -------
    // c code
    struct Person
    {
    int size;
    int height;
    char firstinitial;
    }
    --------
    // java code
    //description in java:
    String[] PersonDescription =
    { "int", "size",
    "int", "height",
    "char", "firstinitial"
    }
    -----------
    then you could have get/set methods that allowed this sort of thing in
    java

    data = (something from a c program)
    data.setType(PersonDescription)'

    x = data.getInt("size") // this would figure out the
    // offset and give you the correct value




    (Please go easy on my syntax, I use lots of languages.)

    -Rick
     
    Rick Giuly, Nov 13, 2004
    #1
    1. Advertising

  2. Rick Giuly wrote:

    > I'm thinking about making a program in java that will allow you to use
    > C data-structures (probably read from a network) easily:


    C structs are not portable, because data type lenghts, endianness and especially
    alignments differ between platforms and compilers.
     
    Michael Borgwardt, Nov 13, 2004
    #2
    1. Advertising

  3. Rick Giuly wrote:
    > I'm thinking about making a program in java that will allow you to use
    > C data-structures (probably read from a network) easily


    <http://jade.dautelle.com/api/jade/util/Struct.html>
     
    Thomas Schodt, Nov 13, 2004
    #3
  4. Rick Giuly

    Chris Uppal Guest

    Michael Borgwardt wrote:

    > > I'm thinking about making a program in java that will allow you to use
    > > C data-structures (probably read from a network) easily:

    >
    > C structs are not portable, because data type lenghts, endianness and
    > especially alignments differ between platforms and compilers.


    That just means that you'd need some way of parameterising the code with
    settings reflecting the known behaviour of some specific compiler(s).
    Perfectly doable, and even sensible.

    I agree that you don't want to get into a position where you are dependent on
    the unspecified behaviour of a C compiler in the first place. But if you /are/
    in that position then centralising and encapsulating the required knowledge in
    (the configuration of) some tool or library seems like a Good Idea to me.

    -- chris
     
    Chris Uppal, Nov 13, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dennis Gavrilov
    Replies:
    1
    Views:
    1,458
    Dennis Gavrilov
    Jul 24, 2003
  2. Gerry
    Replies:
    4
    Views:
    574
    Gerry
    Mar 23, 2005
  3. Darren
    Replies:
    6
    Views:
    424
    Darren
    Jun 15, 2005
  4. tweak
    Replies:
    14
    Views:
    2,796
    Eric Sosman
    Jun 11, 2004
  5. Alfonso Morra
    Replies:
    11
    Views:
    730
    Emmanuel Delahaye
    Sep 24, 2005
Loading...

Share This Page