精華區beta Programming 關於我們 聯絡資訊
※ 引述《march20.bbs@ptt.cc》之銘言: > ※ 引述《costbook (antitheist)》之銘言: > 查了一下 wikipedia 覺得以下這段話滿合理的: > (出自 http://en.wikipedia.org/wiki/Evaluation_strategy ) > ... > 就看你怎樣看待 poiner 和 reference 囉. 其實這種東西並沒有怎麼看待的問題, 分兩個 case 討論: (1) 如果你 pass 的是一個 pointer variable, function 接到的是 pointer 的 rvalue。 (2) 如果你 pass 的是一個 pointer constant (or temporary pointer), function 接到的還是它的 rvalue(因為這類東西規定不能 pass lvalue)。 而你 pass array 或 function name 過去, 會有一個 coercion 把它轉成 pointer 才真的丟進去, 所以和上面的 (2) 是相同的結果, 不管怎麼搞結論都是 by value。 C++ 的 call by reference 是 pass variable 的 lvalue, 你 call arugment 寫 x 這個變數名稱, function 接收到的是 x 的 lvalue, 而在 C 只能 pass &x 這種 temporary pointer 的 rvalue 過去, 既然丟過去的是 argument 的 rvalue, 就不能叫做 by reference, 所以其實完全沒有任何爭議。 -- Name: Tseng, Ling-hua E-mail Address: uranus@it.muds.net School: National Tsing Hua University Department: Computer Science Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design Researching: Undecided Homepage: https://it.muds.net/~uranus -- ╔═══╗ ┼────────────────────────╮ 狂狷 Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮ 年少 ┼╮ < IP:140.119.164.16 > ╰─╮ ╚╦═╦╝ From:61-230-222-238.dynamic.hinet.net ─╨─╨─ KGBBS 遨翔"BBS"的狂狷不馴;屬於年少的輕狂色彩 [修改]tinlans:61-230-222-238.dynamic.hinet.net 06/10/02 18:58:55
march20:對啊, 應該是這樣講才對 128.54.43.37 10/03 05:34
march20:看來 java 也只有 call-by-value 128.54.43.37 10/03 05:34