Rockbox Development > Starting Development and Compiling
Why C?
Llorean:
No, JAVA would never produce the same executable code, because java (when used as intended) isn't compiled to assembly, it's compiled to byte code which then an interpreter deals with and executes code, which is one of the primary reasons it's essentially physically impossible for java to be as efficient at C or C++.
Edit for technical correctness: java can be faster than C or C++, in some general use, because the interpreter can be pre-optimized in some ways. But a C or C++ program properly handled should always be able to perform faster than a JAVA program doing the same thing, if enough time and effort is spent, while ava has some advantages for the more general cases.
In an ideal world C and C++ would be create identical executable code when given identical algorithms, but then identical algorithms in C and C++ would probably *be* identical code. ;)
But yeah, the distinction between C and C++ is more that C, being a "simpler" language keeps the coder more explicit, while C++ lends one to abstractions that, while often making the code "easier" to read (I put such words in quotes, because they're very subjective) tends to leave the code less explicit and more generalized, as the intent with C++ is for the programmer to write in an "object oriented" manner.
mnhnhyouh:
--- Quote from: Llorean on December 04, 2007, 07:39:49 PM ---No, JAVA would never produce the same executable code, because java (when used as intended) isn't compiled to assembly, it's compiled to byte code which then an interpreter deals with and executes code,
--- End quote ---
But doesnt this ultimately have to be approximately the same code? (It has been 20 years since I studied programming in any formal sense.)
h
safetydan:
Well sort of, but Java takes the long way round to get there. C/C++ will be much closer to the final machine code representation. Assembly closer still.
zajacattack:
So, the lower-level the code, generally, the closer to exact machine code right? The most efficient would be to program in machine code, but as this is pretty much impossible, the code ends up being, in order from most to least efficient:
(1) Assembly
(2) C
(3) C++
(4) Java
(5) C#
...
I am correct, right?
cool_walking_:
Well it also depends on the compiler. If you had a real crappy C compiler, and an awesome Java compiler, the Java code would run faster.
You could write something in assembly badly, or write something in C, that the compiler optimises very well.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version