• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

bytecode in c language?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we generate bytecode in c language?...how...?
 
Marshal
Posts: 72048
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure I understand the question.
If you have input code in C and wish to convert it to Java™ bytecode, I am sure you can write a compiler which will do that. Whether you can write char *word = "Campbell"; in that grammar, I don't know.

The usual C compilers do not produce bytecode.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on what you mean by "generate bytecode in c language". A class file is just a binary file - it can be created in any language if you're careful to put the bytes in the correct order so that the output is a valid class file.

You could also check out NestedVM, which translates C programs (and some other source languages) into class files.

If neither of these fits the bill, provide more detail about what it is you're trying to accomplish.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally, when you write a program in C, you would compile it to native code directly.

Compiling to bytecode and then compiling the bytecode to native code at runtime, as the JVM does with its JIT compiler, does have some advantages over compiling to native code directly. In principle, the JIT compiler can generate more efficient code than an ahead-of-time compiler, because the JIT compiler knows more about the system that the code is running on than an ahead-of-time compiler can know. A JIT compiler can optimize the code for the specific processor that the program is running on (an ahead-of-time compiler doesn't know in advance what exact processor the user is going to run the program on), and can do optimizations based on profiling information that only exists when the program is run.

There is a project called LLVM which compiles C, C++ and source code in other programming language to a kind of bytecode, which can be converted to native machine code at runtime, in the same way as the JVM works. Apple is using LLVM on Mac OS X, and it seems to be the next generation of C and C++ compilers. One of the things they can do with this is dynamically compile programs to run on different kinds of processors, for example on the CPU or on the GPU (the processor on the graphics card).

Note however that LLVM bytecode doesn't run on the JVM; the principle is the same, but it really doesn't have anything to do with Java bytecode.
 
We noticed he had no friends. So we gave him this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic