Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Combining C and java

Reply
Thread Tools

Combining C and java

 
 
John Eskie
Guest
Posts: n/a
 
      09-21-2003
I'm trying to do something which I'm not sure is even possible.

I made a code generator which has a C/C++ output writer module and will in
future also have a java output writer module.
These modules will write out source code.

The generated code will need a runtime engine which is small and must be
written in the native language. I wrote one for C and now I'd like to reuse
the same source for java.

I'm unsure if there are any C compilers that can generate java bytecode but
a preprocessor would probably do in my case.

What I have in mind is something like:

typedef struct _foo
{
unsigned char H1[24];
unsigned char H2[24];
} foo;

becomming something like:

#ifdef JAVA
#define U1 byte
#else
#define U1 unsigned char
#endif

#ifdef JAVA
class foo
#else
typedef struct _foo
#endif
{
U1 H1[24];
U2 H2[24];
}
#ifndef JAVA
foo;
}

Atleast something along those lines.

The idea is to twist out those minor differences between the languages.
Before someone says this is impossible I'd like to say that my runtime will
be very small and won't have every possible language feature included so
there should be a chance to develop it.
The alternative is to have 2 codebases but thats bad if you want to have
them in sync.

Thanks in advance.
-- John


 
Reply With Quote
 
 
 
 
kim bruning
Guest
Posts: n/a
 
      09-22-2003
John Eskie <> wrote:
> I'm trying to do something which I'm not sure is even possible.


> I made a code generator which has a C/C++ output writer module and will in
> future also have a java output writer module.
> These modules will write out source code.


> The generated code will need a runtime engine which is small and must be
> written in the native language. I wrote one for C and now I'd like to reuse
> the same source for java.


> I'm unsure if there are any C compilers that can generate java bytecode but
> a preprocessor would probably do in my case.


I wonder if you can configure gcc to do this?

searching:

fsf/unesco free software directory:
http://www.gnu.org/directory/GNU/

free software directory reference to gcc:
http://www.gnu.org/directory/gcc.html

gcc homepage:
http://gcc.gnu.org/

relevant information to be found at:

gcc for java:
http://gcc.gnu.org/java/index.html


Please drop me a mail if you can get it to work!


hope this helps,
read you soon,
Kim


--
Fingerprint for GPG (www.gnupg.org) key EDDE AA07 :
BA7F BF9D 8F70 6031 D9E4 14A1 AD0F 180F EDDE AA07
 
Reply With Quote
 
 
 
 
John Eskie
Guest
Posts: n/a
 
      09-22-2003
> I wonder if you can configure gcc to do this?
>


Thanks for the suggestion but I don't think it can be done with gcc itself.

GCC seems not to be able to generate java binary code. Atleast I didn't find
it yet.

There is a frontend for GCC which you gave a link for which is called GCJ.
This is just another java compiler with the feature of beeing able to
produce native code from java source code. This is not really useful to me
unfortunatly.
The whole reason for me writing the runtime in C is to make it native code
for multiply platforms. Switching to java will not allow me that.

-- John


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-22-2003
On Mon, 22 Sep 2003 20:03:32 +0200, "John Eskie"
<> wrote or quoted :

>GCC seems not to be able to generate java binary code. Atleast I didn't find
>it yet.


not very likely. It would have to be a subset of C. Java has a strong
safety net which is visible in the JVM. C lets you do many dangerous
and platform specific things.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      09-23-2003
John Eskie wrote:

> I made a code generator which has a C/C++ output writer module and will in
> future also have a java output writer module.
> These modules will write out source code.
>
> The generated code will need a runtime engine which is small and must be
> written in the native language. I wrote one for C and now I'd like to
> reuse the same source for java.


My gut feeling is that you'd be wasting your time -- the languages are much too
different for it to be worthwhile trying to mask the differences, and that
you'd be spending longer trying to shoehorn the two together than you'd be
saving by having two different code-bases (at least when they are both small,
as you say).

Why not try this ? Write (in whatever language you fancy) a pre-processor that
converts your existing C engine into rough Java. If you find that you can do a
complete conversion and you are happy with the end result, then keep your
converter tool and re-use it in the future. But if you find that it's
difficult to do *all* the conversions, then settle for something that just does
90% of the dog-work, and then finish the conversion off by hand. That'll leave
you with two code bases, but the bulk of the effort has been done for you by
the script.

-- chris



 
Reply With Quote
 
kim bruning
Guest
Posts: n/a
 
      10-21-2003
My apologies for this late response. I've recently switched ISPs, and
things tend to get lost in-between.

John Eskie wrote:
>>I wonder if you can configure gcc to do this?
>>

>
>
> Thanks for the suggestion but I don't think it can be done with gcc itself.
>
> GCC seems not to be able to generate java binary code. Atleast I didn't find
> it yet.


It looks like you're right. Apparently it *is* possible to configure gcc
to target quite a number of different binary platforms, see:

http://gcc.gnu.org/install/specific.html

for instance. Just not for jvm, yet, apparently.

It actually surprises me that nobody has thought to add support for the
jvm as a target platform yet.

I've heard stories that it isn't entirely too hard to add support for
additional platforms to GCC. The fact that so many platforms are already
supported is testament to this.

If you're still interested in generating code to a jvm target, perhaps
it might be interesting to contact the gcc team and pose it as a
suggestion? They'd likely be able to tell you how hard it is to add the
option to their compiler.


I hope this is still of some use,
sincerely,
Kim Bruning

 
Reply With Quote
 
kim bruning
Guest
Posts: n/a
 
      10-21-2003
My apologies for this late response. I've recently switched ISPs, and
things tend to get lost in-between.

John Eskie wrote:
>>I wonder if you can configure gcc to do this?
>>

>
>
> Thanks for the suggestion but I don't think it can be done with gcc itself.
>
> GCC seems not to be able to generate java binary code. Atleast I didn't find
> it yet.


It looks like you're right. Apparently it *is* possible to configure gcc
to target quite a number of different binary platforms, see:

http://gcc.gnu.org/install/specific.html

for instance. Just not for jvm, yet, apparently.

It actually surprises me that nobody has thought to add support for the
jvm as a target platform yet.

I've heard stories that it isn't entirely too hard to add support for
additional platforms to GCC. The fact that so many platforms are already
supported is testament to this.

If you're still interested in generating code to a jvm target, perhaps
it might be interesting to contact the gcc team and pose it as a
suggestion? They'd likely be able to tell you how hard it is to add the
option to their compiler.


I hope this is still of some use,
sincerely,
Kim Bruning

 
Reply With Quote
 
Mike Yawn
Guest
Posts: n/a
 
      10-21-2003
kim bruning wrote:
> My apologies for this late response. I've recently switched ISPs, and
> things tend to get lost in-between.
>
> John Eskie wrote:
>
>>> I wonder if you can configure gcc to do this?
>>>

>>
>>
>> Thanks for the suggestion but I don't think it can be done with gcc
>> itself.
>>
>> GCC seems not to be able to generate java binary code. Atleast I
>> didn't find
>> it yet.

>
>
> It looks like you're right. Apparently it *is* possible to configure gcc
> to target quite a number of different binary platforms, see:
>
> http://gcc.gnu.org/install/specific.html
>
> for instance. Just not for jvm, yet, apparently.
>
> It actually surprises me that nobody has thought to add support for the
> jvm as a target platform yet.
>
> I've heard stories that it isn't entirely too hard to add support for
> additional platforms to GCC. The fact that so many platforms are already
> supported is testament to this.
>
> If you're still interested in generating code to a jvm target, perhaps
> it might be interesting to contact the gcc team and pose it as a
> suggestion? They'd likely be able to tell you how hard it is to add the
> option to their compiler.
>
>
> I hope this is still of some use,
> sincerely,
> Kim Bruning
>


I suspect it would be very difficult to get a C compiler to target the
JVM. The JVM bytecodes were designed to implement a strongly-typed
language (Java). While compilers for other strongly-typed languages
might be able to target the JVM, I can't imagine how some of the crap C
allows you to get away with could be mapped to a valid bytecode sequence.

Mike

 
Reply With Quote
 
Jezuch
Guest
Posts: n/a
 
      10-21-2003
Mike Yawn wrote:
> I suspect it would be very difficult to get a C compiler to target the
> JVM. The JVM bytecodes were designed to implement a strongly-typed
> language (Java). While compilers for other strongly-typed languages
> might be able to target the JVM, I can't imagine how some of the crap C
> allows you to get away with could be mapped to a valid bytecode sequence.


But GCC is *not* a C compiler. It is among others a C compiler It can
also compile C++, Ada, Fortran and Java, both to native and byte-code.

see http://www.gnu.org/software/gcc/java/

"GCJ is a portable, optimizing, ahead-of-time compiler for the Java
Programming Language. It can compile:
* Java source code directly to native machine code,
* Java source code to Java bytecode (class files),
* and Java bytecode to native machine code."
--
Ecce Jezuch
"I think I'll lie here for a while.
Then, after that...
I think I'll lie here for a while." - Garfield

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      10-21-2003
On Sun, 21 Sep 2003 20:53:32 +0200, John Eskie wrote:
> I'm unsure if there are any C compilers that can generate java
> bytecode but a preprocessor would probably do in my case.


Do any of these help?

http://jazillian.com/index.html
http://jazillian.com/competition.html
http://grunge.cs.tu-berlin.de/~tolk/vmlanguages.html

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Java Reflection API with Java Annotation Types for Thread Safety pek Java 2 10-23-2007 03:00 PM
Combining The Best Of Python, Ruby, & Java?????? Tim Daneliuk Python 9 06-13-2006 08:30 PM
Combining numeric mode paging and nextPreview paging in datagrid Red ASP .Net 1 03-12-2005 11:41 PM
T-bird and combining messages Dudhorse Firefox 2 11-12-2004 11:55 PM
Combining forms and Windows authentication Nils Magnus Englund ASP .Net 0 04-19-2004 12:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57