• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            asm, c, c++ are my all
            -- Core In Computer
            posts - 139,  comments - 123,  trackbacks - 0

            /********************************************\
            |????歡迎轉載, 但請保留作者姓名和原文鏈接, 祝您進步并共勉!???? |
            \********************************************/


            1.2 A Keyword Distinction

            作者: Jerry Cat
            時間: 2006/04/20
            鏈接: http://www.shnenglu.com/jerysun0818/archive/2006/04/22/6064.html

            -------------------------
            unequivocal: 毫不含糊的
            pedestrian:? 步行者; 步行的, 呆板的, 通俗的
            infamous:??? 聲名狼藉的
            strike aside:閃躲開
            brandish:??? 揮舞(n. & v.)
            fledgling:?? n.羽毛初長的雛鳥, 羽翼未豐無經驗的人, 初出茅廬的人
            underpinning:基礎, 支柱, 支撐
            discourse:?? 談話, 演說, 演講, 論文(n. & v.)

            C++的struct 與 class有惱人的曖昧關系, 表面上struct里沒顯式說明存儲權限的全是public而class則全是private, 事實卻并非如此簡單當考慮到與C的兼容時, 尤其是對待C中的tricks時, 更是traps多多, 地雷密布!

            A C program's trick is sometimes a C++ program's trap. One example of this is the use of a one-element array at the end of a struct to allow individual struct objects to address variable-sized arrays:

            struct mumble {
            ?? /* stuff */
            ?? char pc[ 1 ];
            };

            // grab a string from file or standard input
            // allocate memory both for struct & string

            struct mumble *pmumb1 = ( struct mumble* )
            ?? malloc(sizeof(struct mumble)+strlen(string)+1);//在C中內存連續分布的, 但若考慮到
            ?? //這是在C++中, struct基本上就是類, 這類的數據成員與外來(參)變量的"tricky 捆綁式"
            ?? //內存布局將導致派生類的數據成員"插不進去"從而導致類的數據成員內存布局不連續!
            ?? //所以C的trick是非標準的不能濫用!

            strcpy( &mumble.pc, string );
            This may or may not translate well when placed within a class declaration that

            1). specifies multiple access sections containing data,
            2). derives from another class or is itself the object of derivation, or
            3). defines one or more virtual functions.

            The data members within a single access section are guaranteed within C++ to be laid out in the order of their declaration. The layout of data contained in multiple access sections, however, is left undefined. In the following declaration, for example, the C trick may or may not work, depending on whether the protected data members are placed before or after those declared private:

            class stumble {
            public:
            ?? // operations ...
            protected:
            ?? // protected stuff
            private:
            ?? /* private stuff */
            ?? char pc[ 1 ];
            };
            ?
            Similarly, the layout of data members of the base and derived classes is left undefined, thereby also negating any guarantee that the trick might work. The presence of a virtual function also places the trick's viability in question. The best advice is not to do it. (Chapter 3 discusses these layout issues in greater detail.)

            //接上
            If a programmer absolutely needs a data portion of an arbitrarily complex C++ class to have the look and feel of an equivalent C declaration, that portion is best factored out into an independent struct declaration. The original idiom for combining this C portion with its C++ part (see [KOENIG93]) was to derive the C++ part from the C struct:

            struct C_point { ... };
            class Point : public C_point { ... };
            thus supporting both the C and C++ usage:

            extern void draw_line( Point, Point );
            extern "C" void draw_rect ( C_point, C_Point );

            draw_line( Point( 0, 0 ), Point( 100, 100 ));
            draw_rect( Point( 0, 0 ), Point( 100, 100 ));
            This idiom is no longer recommended, however, because of changes to the class inheritance layout in some compilers (for example, the Microsoft C++ compiler) in support of the virtual function mechanism (see Section 3.4 for a discussion). Composition, rather than inheritance, is the only portable method of combining C and C++ portions of a class (the conversion operator provides a handy extraction method):

            struct C_point { ... };

            class Point {
            public:
            ?? operator C_point() { return _c_point; }
            ?? // ...
            private:
            ?? C_point _c_point;
            ?? // ...
            };

            強烈不推薦這種種"淫巧",? 不過在C/C++混合編程時你還不得不用它:)
            One reasonable use of the C struct in C++, then, is when you want to pass all or part of a complex class object to a C function. This struct declaration serves to encapsulate that data and guarantees a compatible C storage layout. This guarantee, however, is maintained only under composition. Under inheritance, the compiler decides whether additional data members are inserted within the base struct subobject (again, see Section 3.4 for a discussion, as well as Figures 3.2(a) and 3.2(b)).

            posted on 2006-04-22 01:23 Jerry Cat 閱讀(610) 評論(0)  編輯 收藏 引用

            <2006年4月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            常用鏈接

            留言簿(7)

            隨筆檔案

            最新隨筆

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久午夜无码鲁丝片| 久久久久四虎国产精品| 久久久久国产| 久久人妻少妇嫩草AV蜜桃| 久久精品国产亚洲av影院| 久久精品国产久精国产| 久久久久无码精品国产app| 无码日韩人妻精品久久蜜桃| 久久精品中文騷妇女内射| 狠狠人妻久久久久久综合蜜桃| 亚洲日韩欧美一区久久久久我| 久久久久久国产精品无码超碰 | 国产激情久久久久影院| 青青草原综合久久大伊人导航| 精品久久久无码人妻中文字幕| 久久精品国产一区二区三区日韩| 欧美精品福利视频一区二区三区久久久精品 | 婷婷久久五月天| 久久精品男人影院| 综合久久国产九一剧情麻豆| 国产精品美女久久久久AV福利| 亚洲伊人久久精品影院| 一级做a爰片久久毛片免费陪| 日本精品久久久久中文字幕8| 久久久婷婷五月亚洲97号色| 国内精品久久国产| 久久精品国产精品亚洲| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 久久人妻少妇嫩草AV无码蜜桃| 久久精品中文騷妇女内射| 亚洲国产精品一区二区久久hs| 无码伊人66久久大杳蕉网站谷歌| 久久频这里精品99香蕉久| 精品久久香蕉国产线看观看亚洲 | 亚洲精品综合久久| 久久精品国产99国产精偷| 久久婷婷五月综合色奶水99啪| 午夜人妻久久久久久久久| 亚洲成色www久久网站夜月| 久久中文字幕人妻丝袜| 欧美亚洲国产精品久久高清|