okuの日記: 2 + 2 = ?
artima Developer は PHP Buzz forum 経由、jimbojw.com は What is two plus two? より:
元記事では、
- Ruby
- JavaScript
- Java
- PHP
を例にとって、様々な「2 + 2」の結果を挙げています。 というわけで、私は CINT の例を挙げてみようかなと。
$ cint
cint : C/C++ interpreter (mailing list 'cint@root.cern.ch')
Copyright(c) : 1995~2005 Masaharu Goto (gotom@hanno.jp)
revision : 5.16.19, March 16, 2007 by M.Goto
No main() function found in given source file. Interactive interface started.
'?':help, '.q':quit, 'statement','{statements;}' or '.p [expr]' to evaluate
cint> 2 + 2
(const int)4
cint> 2 + 2.0
(const double)4.00000000000000000e+00
cint> 2 + "2"
(const char* 0x503650)""
cint> 2.0 + 2
(const double)4.00000000000000000e+00
cint> 2.0 + 2.0
(const double)4.00000000000000000e+00
cint> 2.0 + "2"
(const double)5.25677800000000000e+06
cint> "2" + 2
(const char* 0x50364a)""
cint> "2" + 2.0
(const double)5.25677800000000000e+06
cint> "2" + "2"
Error: + Illegal operator for pointer 1 (tmpfile):1:
(const char* 0x503648)"2"
*** Interpreter error recovered ***
cint> .q
Bye... (try 'qqq' if still running)
$
だから何、と言われても困るのですが... "2" + 2.0 の結果はちょっと合点がいかないかなぁ、という感じがします (多分、(double)((int)("2")) + 2.0 の結果だろうと思うのですが)。
まあ、少なくとも文字列連結に「+」を使うのはヨクナイのではないかと思ったりなんかするわけですよ。 > ダートマス大学の人とか Stroustrup 尊師とか
# Perl の人がそういうことを書いていたような記憶があります。
2 + 2 = ? More ログイン