<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    開花流水

    空山無人,水流花開。

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      79 Posts :: 42 Stories :: 160 Comments :: 0 Trackbacks

    這些最為奇怪的程序語言的特性,來自stackoverflow.com,原貼在這里。我摘選了一些例子,的確是比較怪異,讓我們一個一個來看看。

    1、C語言中的數組

    在C/C++中,a[10] 可以寫成 10[a]

    “Hello World”[i] 也可以寫成 i["Hello World"] 

    2、在Javascript中 

     ’5′ + 3 的結果是:’53′

     ’5′ – 3 的結果是:2              更多javascript點擊這里

    3、C/C++中的Trigraphs 

    Cpp代碼  收藏代碼
    1. int main() {  
    2.     cout << "LOL??!";  
    3. }  

     上面的這段程序會輸出: “LOL|”,這是因為 ??! 被轉成了 | ,關于Trigraphs,下面有個表格: 

    ??= #
    ??( [
    ??/ \
    ??) ]
    ??’ ^
    ??< {
    ??! |
    ??> }
    ??- ~

    4、JavaScript 的條件表 

    看到下面這個表,不難理解為什么Javascript程序員為什么痛苦了

    Js代碼  收藏代碼
    1. ''        ==   '0'          //false  
    2. 0         ==   ''           //true  
    3. 0         ==   '0'          //true  
    4. false     ==   'false'      //false  
    5. false     ==   '0'          //true  
    6. false     ==   undefined    //false  
    7. false     ==   null         //false  
    8. null      ==   undefined    //true  
    9. " \t\r\n" ==   0            //true  

     

    5、Java的Integer cache

    Java代碼  收藏代碼
    1. Integer foo = 1000;  
    2. Integer bar = 1000;  
    3.   
    4. foo <= bar; // true  
    5. foo >= bar; // true  
    6. foo == bar; // false  
    7.   
    8. //然后,如果你的 foo 和 bar 的值在 127 和 -128 之間(包括)  
    9. //那么,其行為則改變了:  
    10.   
    11. Integer foo = 42;  
    12. Integer bar = 42;  
    13.   
    14. foo <= bar; // true  
    15. foo >= bar; // true  
    16. foo == bar; // true  

    為什么會這樣呢?你需要了解一下Java Interger Cache,下面是相關的程序,注意其中的注釋

    Java代碼  收藏代碼
    1. /** 
    2.  
    3.      * Returns a <tt>Integer</tt> instance representing the specified 
    4.  
    5.      * <tt>int</tt> value. 
    6.  
    7.      * If a new <tt>Integer</tt> instance is not required, this method 
    8.  
    9.      * should generally be used in preference to the constructor 
    10.      * <a href="mailto:{@link">{@link</a> #Integer(int)}, as this method is likely to yield 
    11.      * significantly better space and time performance by caching 
    12.      * frequently requested values. 
    13.      * 
    14.      * @param  i an <code>int</code> value. 
    15.      * @return a <tt>Integer</tt> instance representing <tt>i</tt>. 
    16.      * @since  1.5 
    17.      */  
    18.     public static Integer valueOf(int i) {  
    19.         if(i >= -128 && i <= IntegerCache.high)  
    20.             return IntegerCache.cache[i + 128];  
    21.         else  
    22.             return new Integer(i);  
    23.     }  

    5、Perl的那些奇怪的變量

    Php代碼  收藏代碼
    1. $.  
    2. $_  
    3. $_#  
    4. $$  
    5. $[  
    6. @_  

     其所有的這些怪異的變量請參看:http://www.kichwa.com/quik_ref/spec_variables.html

     

    6、Java的異常返回

    請看下面這段程序,你覺得其返回true還是false?

    Java代碼  收藏代碼
    1. try {  
    2.     return true;  
    3. finally {  
    4.     return false;  
    5. }  

     在 javascript 和python下,其行為和Java的是一樣的。 

    7、C語言中的Duff device

    下面的這段程序你能看得懂嗎?這就是所謂的Duff Device,相當的怪異。

    C代碼  收藏代碼
    1. void duff_memcpy( char* to, char* from, size_t count ) {  
    2.     size_t n = (count+7)/8;  
    3.     switch( count%8 ) {  
    4.     case 0: do{ *to++ = *from++;  
    5.     case 7:     *to++ = *from++;  
    6.     case 6:     *to++ = *from++;  
    7.     case 5:     *to++ = *from++;  
    8.     case 4:     *to++ = *from++;  
    9.     case 3:     *to++ = *from++;  
    10.     case 2:     *to++ = *from++;  
    11.     case 1:     *to++ = *from++;  
    12.             }while(--n>0);  
    13.     }  
    14. }   

    8、PHP中的字符串當函數用

    PHP中的某些用法也是很怪異的

    Php代碼  收藏代碼
    1. $x = "foo";  
    2. function foo(){ echo "wtf"; }  
    3. $x();  

    9、在C++中,你可以使用空指針調用靜態函數

    Cpp代碼  收藏代碼
    1. class Foo {  
    2.   public:  
    3.     static void bar() {  
    4.       std::cout << "bar()" << std::endl;  
    5.     }  
    6. };  

    呵呵。的確是挺怪異的。

    轉自iteye
    http://justjavac.iteye.com/blog/1297756
    posted on 2011-12-21 14:49 開花流水 閱讀(147) 評論(0)  編輯  收藏 所屬分類: 軟件
    主站蜘蛛池模板: 亚洲av无码一区二区三区人妖| 久热综合在线亚洲精品| 亚洲综合精品伊人久久| 91成人免费在线视频| 亚洲精品无码久久久久久久 | 亚洲精品视频在线观看免费| 精品国产麻豆免费人成网站| 亚洲成AV人片一区二区| 久久A级毛片免费观看| 18gay台湾男同亚洲男同| 91青青青国产在观免费影视| 亚洲国产夜色在线观看| 成年大片免费视频| 国产精品亚洲lv粉色| 亚洲第一视频在线观看免费| 成年女人毛片免费播放人| 亚洲五月综合缴情婷婷| 99精品国产免费久久久久久下载 | 1000部拍拍拍18勿入免费视频软件 | 亚洲最大成人网色| 免费国产作爱视频网站| 亚洲啪AV永久无码精品放毛片 | 免费看a级黄色片| 日本在线观看免费高清| 亚洲国产成人精品无码区在线观看 | a级片免费在线播放| 久久亚洲国产精品成人AV秋霞 | 日韩激情无码免费毛片| 人人爽人人爽人人片av免费 | 亚洲啪AV永久无码精品放毛片| 国产伦精品一区二区三区免费迷| 国产福利免费视频 | 亚洲一级毛片在线播放| 全部免费国产潢色一级| 叮咚影视在线观看免费完整版| 亚洲av无码片在线观看| 亚洲人成电影在线播放| 最近2019免费中文字幕视频三| 亚洲av无码成人影院一区| 亚洲AV无码一区二区乱子伦| 国外成人免费高清激情视频|