Re: [問題] 比較C語言與Java
※ 引述《JohnBintan (Begins)》之銘言:
: 不知道po在這裡合不合適...
: 小弟其實只懂得C語言
: 以下四句話, 我不知道哪些是對的哪些是錯的...
: 可以請眾版友位我解答嗎? 謝謝
: 1. C passes parameters in registers while Java passes them on the stack.
C的話看calling convention
現在的VC只有fastcall會把前兩個參數丟進register
一般的cdecl同樣是推進stack的
其他的compiler就不清楚了
Java的話 因為它是bytecode 不是machine code
我覺得(既然都已經是自成一格的bytecode了)應該是會推進stack的
(也就是不會分calling convention 一律推進stack)
(以C的說法來看 Java的函式呼叫都是thiscall)
: 2. Strings are just an informal name for single-dimention arrays of characters
: in C and Java.
for C, yes
for Java(and C++), 看實作 因為那是一個class, 是包起來的
: 3. Strings in C and Java use null(0) to mark the end of a string.
for C, yes
for Java, 一樣是看實作
: 4. Operations on strings, like length, are faster in C than in Java.
如果字串是像Basic裡的字串把長度另外紀錄的 那在長字串取長度時是會稍快
C是zero-terminated 所以要取長度就要一個一個算
所以基本上C似乎並不會比較快...
--
似乎對Java的結論都是要去看實作...XD
反正已經有包好的東西就拿來用了嘛 還管它裡面是怎麼存的 (個人想法)
--
実琴:「河野!你真的就這樣被物質慾望給吸引過去了嗎?!」
亨:「只要穿著女裝擺出親切的樣子,所有必要花費就能全免,似乎一點都不壞啊。」
実琴:「難道你沒有男人的尊嚴了嗎?!」
亨:(斷然道)「沒有。在節衣縮食且生活吃緊的學生面前,沒有那種東西。」
--プリンセス・プリンセス 第二話
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 192.192.197.115
討論串 (同標題文章)