3

I want to create some simple C code from Java, and I was wondering if there are some libraries that could help me. Sadly my google skills are not too good and my results are way off. ("C libraries for Java", "creating c code in java", etc).

My idea would be something like create C file and use method createMethod(name, argument, return, code) instead of having to just create a document and write strings like

return name(argument) {
   code
}

Nevertheless, I am little pessimistic and I think that most probably I will just have to create the C code by creating a document, and writing into it the c lines.

Juan
  • 521
  • 1
  • 11
  • 28
  • What advantage do you see in this approach that the code written in C doesn't give to you? – Daniel Pereira Feb 12 '13 at 16:20
  • The advantage is that the C code is simple, but the way its generated is non-trivial, dynamic and automatic; therefore, I use Java in which I have more experience. If I used C, I would still like some kind of library help. @BalusC not sure if I expressed it right, the main project is Java and I need to create a few 100-200 lines of C code (in 2+ files) – Juan Feb 12 '13 at 17:00
  • 1
    See http://stackoverflow.com/questions/3455456/how-to-translate-between-programming-languages/3460977#3460977 – Ira Baxter Feb 12 '13 at 21:49
  • Interesting reading, and I do agree on the complexity of automatic code translation. I just figure maybe someone had written a library to write simple C files. So far I have not been able to find any, and inputting to a text files seems to be the nasty but easy way to do it. – Juan Feb 13 '13 at 09:12

1 Answers1

1

One can use JCodeModel to create (Java) source code. You could create your own C targeted API mimicking the JCodeModel API. Maybe even extend the JCodeModel classes.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • Sounds interesting, I will take a look. Seems like if I don't get an already done library, then maybe I could use this to create a C-library/API. I hope it wont be too hard to do. – Juan Feb 12 '13 at 17:06