锘??xml version="1.0" encoding="utf-8" standalone="yes"?>97久久精品亚洲中文字幕无码,亚洲精品亚洲人成在线观看,亚洲成人高清在线观看http://www.tkk7.com/zhaochengming/category/26802.html 鐭ユ鑰屽悗鏈夊畾錛屽畾鑰屽悗鑳介潤錛岄潤鑰屽悗鑳藉畨錛屽畨鑰屽悗鑳借檻錛岃檻鑰屽悗鑳藉緱銆傜墿鏈夋湰鏈紝浜嬫湁緇堝銆傜煡鎵鍏堝悗錛屽垯榪戦亾鐭c?/description>zh-cnTue, 23 Mar 2010 04:01:45 GMTTue, 23 Mar 2010 04:01:45 GMT60c++涓璫onst鍏抽敭瀛椾嬌鐢ㄨ瑙?杞嚜http://hi.baidu.com/nanting520/blog/item/28df02821bb9e793f703a6e1.htmlhttp://www.tkk7.com/zhaochengming/archive/2009/02/06/253499.htmlhelloworld2008helloworld2008Fri, 06 Feb 2009 02:27:00 GMThttp://www.tkk7.com/zhaochengming/archive/2009/02/06/253499.htmlhttp://www.tkk7.com/zhaochengming/comments/253499.htmlhttp://www.tkk7.com/zhaochengming/archive/2009/02/06/253499.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/253499.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/253499.htmlc++涓璫onst鍏抽敭瀛椾嬌鐢ㄨ瑙?/div>
2007-11-17 00:36
鍏充簬C++涓殑const鍏抽敭瀛楃殑鐢ㄦ硶闈炲父鐏墊椿錛岃屼嬌鐢╟onst灝嗗ぇ澶ф敼鍠勭▼搴忕殑鍋ュ.鎬с傚湪緗戜笂鎼滃鐩稿叧涓婚錛屽彂鐜板ぇ澶氭暟鏂囩珷闆峰悓錛岃屽叧閿湴鏂瑰茍涓嶆槸寰堟竻妤氥傚湪緗戠粶璧勬枡錛屽弬鑰冧功鐨勫熀紜涓婏紝緇撳悎鏈漢鐨勪竴浜涗綋浼氭葷粨濡備笅錛屾湡鏈涘澶у鏈夋墍甯姪錛?br />

涓 const鍩虹
涓嬮潰鍥涗釜瀹氫箟璇彞鏄ぇ澶氭暟涔︾睄璁茶Вconst鍏抽敭瀛楅兘浼氱敤鍒扮殑錛?br /> [1]const int* a = &b;
[2]int const *a = &b;
[3]int* const a = &b;
[4]const int* const a = &b;
       濡傛灉浣犺兘鍖哄垎鍑轟笂榪板洓縐嶆儏鍐碉紝璇佹槑浣犲熀紜涓嶉敊錛屼笉榪囦篃涓嶈楂樺叴澶棭錛岃繖涓彧鏄渶鍩虹鐨勯儴鍒嗕簡銆備笉鐭ラ亾涔熷緢瀹規槗錛氬鏋渃onst浣嶄簬鏄熷彿鐨勫乏渚э紙涓嶇const鍦ㄧ被鍨嬩慨楗扮鐨勫乏榪樻槸鍙籌級錛屽垯const灝辨槸鐢ㄦ潵淇グ鎸囬拡鎵鎸囧悜鐨勫彉閲忥紝鍗蟲寚閽堟寚鍚戜負甯擱噺錛涘鏋渃onst浣嶄簬鏄熷彿鐨勫彸渚э紝const灝辨槸淇グ鎸囬拡鏈韓錛屽嵆鎸囬拡鏈韓鏄父閲忋俒1]鍜孾2]鐨勬儏鍐電浉鍚岋紝閮芥槸鎸囬拡鎵鎸囧悜鐨勫唴瀹逛負甯擱噺錛岃繖縐嶆儏鍐典笅涓嶅厑璁稿鍐呭榪涜鏇存敼鎿嶄綔錛屽涓嶈兘*a = 3 錛涜繖鏍風殑涓縐嶅0鏄庢柟寮忕殑浣滅敤鏄彲浠ヤ慨鏀筽i榪欎釜鎸囬拡鎵鎸囧悜鐨勫唴瀛樺湴鍧鍗翠笉鑳戒慨鏀規寚鍚戝璞$殑鍊鹼紱[3]涓烘寚閽堟湰韜槸甯擱噺錛岃屾寚閽堟墍鎸囧悜鐨勫唴瀹逛笉鏄父閲忥紝榪欑鎯呭喌涓嬩笉鑳藉鎸囬拡鏈韓榪涜鏇存敼鎿嶄綔錛屽a++鏄敊璇殑;[4]涓烘寚閽堟湰韜拰鎸囧悜鐨勫唴瀹瑰潎涓哄父閲忋?br />        鍙﹀const 鐨勪竴浜涘己澶х殑鍔熻兘鍦ㄤ簬瀹冨湪鍑芥暟澹版槑涓殑搴旂敤銆傚湪涓涓嚱鏁板0鏄庝腑錛宑onst 鍙互淇グ鍑芥暟鐨勮繑鍥炲鹼紝鎴栨煇涓弬鏁幫紱瀵逛簬鎴愬憳鍑芥暟錛岃繕鍙互淇グ鏄暣涓嚱鏁般傛湁濡備笅鍑犵鎯呭喌錛屼互涓嬩細閫愭笎鐨勮鏄庣敤娉曪細
A_class& operator=(const A_class& a);    //A_class 涓轟竴涓凡緇忓畾涔夌殑綾伙紝涓嬫枃鍚?br /> void fun0(const A_class* a );
void fun1( ) const;    // fun1( ) 涓虹被鎴愬憳鍑芥暟
const A_class fun2( );

浜?const鐨勫垵濮嬪寲
鍏堢湅涓涓媍onst鍙橀噺鍒濆鍖栫殑鎯呭喌
1) 闈炴寚閽坈onst甯擱噺鍒濆鍖栫殑鎯呭喌錛?br /> A_class b;
const A_class a = b;
2) 鎸囬拡(寮曠敤)const甯擱噺鍒濆鍖栫殑鎯呭喌錛?br /> A_class* d = new A_class();
const A_class* c = d;
鎴栬?
const A_class* c = new A_class();
寮曠敤錛?
A_class f;
const A_class& e = f;   // 榪欐牱浣渆鍙兘璁塊棶澹版槑涓篶onst鐨勫嚱鏁幫紝鑰屼笉鑳借闂竴鑸殑鎴愬憳鍑芥暟錛?br /> [鎬濊?]錛?浠ヤ笅鐨勮繖縐嶈祴鍊兼柟娉曟紜悧錛?br /> const A_class* c=new A_class();
A_class* e = c;
榪欑鏂規硶涓嶆紜紝鍥犱負澹版槑鎸囬拡鐨勭洰鐨勬槸涓轟簡瀵瑰叾鎸囧悜鐨勫唴瀹硅繘琛屾敼鍙橈紝鑰屽0鏄庣殑鎸囬拡e鎸囧悜鐨勬槸涓涓父閲忥紝鎵浠ヤ笉姝g‘錛?br /> [鎬濊?]錛?浠ヤ笅鐨勮繖縐嶈祴鍊兼柟娉曟紜悧錛?br /> A_class* const c = new A_class();
A_class* b = c;
榪欑鏂規硶姝g‘錛屽洜涓哄0鏄庢寚閽堟墍鎸囧悜鐨勫唴瀹瑰彲鍙橈紱

涓?浣滀負鍙傛暟鍜岃繑鍥炲肩殑const淇グ絎?br />
鍏跺疄錛屼笉璁烘槸鍙傛暟榪樻槸榪斿洖鍊鹼紝閬撶悊閮芥槸涓鏍風殑錛屽弬鏁頒紶鍏ユ椂鍊欏拰鍑芥暟榪斿洖鐨勬椂鍊欙紝鍒濆鍖朿onst鍙橀噺
1 淇グ鍙傛暟鐨刢onst,濡?
void fun0(const A_class* a );
void fun1(const A_class& a);
璋冪敤鍑芥暟鐨勬椂鍊欙紝鐢ㄧ浉搴旂殑鍙橀噺鍒濆鍖朿onst甯擱噺錛屽垯鍦ㄥ嚱鏁頒綋涓紝鎸夌収const鎵淇グ鐨勯儴鍒嗚繘琛屽父閲忓寲錛屽褰㈠弬涓篶onst A_class* a錛屽垯涓嶈兘瀵逛紶閫掕繘鏉ョ殑鎸囬拡鐨勫唴瀹硅繘琛屾敼鍙橈紝淇濇姢浜嗗師鎸囬拡鎵鎸囧悜鐨勫唴瀹癸紱濡傚艦鍙備負const A_class& a錛屽垯涓嶈兘瀵逛紶閫掕繘鏉ョ殑寮曠敤瀵硅薄榪涜鏀瑰彉錛屼繚鎶や簡鍘熷璞$殑灞炴с?br /> [娉ㄦ剰]錛氬弬鏁癱onst閫氬父鐢ㄤ簬鍙傛暟涓烘寚閽堟垨寮曠敤鐨勬儏鍐?
2 淇グ榪斿洖鍊肩殑const錛屽,
const A_class fun2( ); const A_class* fun3( );
榪欐牱澹版槑浜嗚繑鍥炲煎悗錛宑onst鎸夌収"淇グ鍘熷垯"榪涜淇グ錛岃搗鍒扮浉搴旂殑淇濇姢浣滅敤銆?br /> const Rational operator*(const Rational& lhs, const Rational& rhs)
{
return Rational(lhs.numerator() * rhs.numerator(), lhs.denominator() * rhs.denominator());
}
榪斿洖鍊肩敤const淇グ鍙互闃叉榪欐牱鐨勬搷浣滃彂鐢?
Rational a,b;
Radional c;
(a*b) = c;
涓鑸敤const淇グ榪斿洖鍊間負瀵硅薄鏈韓錛堥潪寮曠敤鍜屾寚閽堬級鐨勬儏鍐靛鐢ㄤ簬浜岀洰鎿嶄綔絎﹂噸杞藉嚱鏁板茍浜х敓鏂板璞$殑鏃跺欍?br /> [鎬葷粨]涓鑸儏鍐典笅錛屽嚱鏁扮殑榪斿洖鍊間負鏌愪釜瀵硅薄鏃訛紝濡傛灉灝嗗叾澹版槑涓篶onst鏃訛紝澶氱敤浜庢搷浣滅鐨勯噸杞姐?br /> 閫氬父錛屼笉寤鴻鐢╟onst淇グ鍑芥暟鐨勮繑鍥炲肩被鍨嬩負鏌愪釜瀵硅薄鎴栧鏌愪釜瀵硅薄寮曠敤鐨勬儏鍐點?br /> 鍘熷洜濡備笅錛氬鏋滆繑鍥炲間負鏌愪釜瀵硅薄涓篶onst錛坈onst A_class test = A_class 瀹炰緥錛夋垨鏌愪釜瀵硅薄鐨勫紩鐢ㄤ負const錛坈onst A_class& test = A_class瀹炰緥錛夛紝鍒欒繑鍥炲煎叿鏈塩onst灞炴э紝鍒欒繑鍥炲疄渚嬪彧鑳借闂被A_class涓殑鍏湁錛堜繚鎶わ級鏁版嵁鎴愬憳鍜宑onst鎴愬憳鍑芥暟錛屽茍涓斾笉鍏佽瀵瑰叾榪涜璧嬪兼搷浣滐紝榪欏湪涓鑸儏鍐典笅寰堝皯鐢ㄥ埌銆?br /> [鎬濊?]錛?榪欐牱瀹氫箟璧嬪兼搷浣滅閲嶈澆鍑芥暟鍙互鍚楋紵
const A_class& operator=(const A_class& a);
涓嶆紜紱鍦╟onst A_class::operator=(const A_class& a)涓紝鍙傛暟鍒楄〃涓殑const鐨勭敤娉曟紜紝鑰屽綋榪欐牱榪炵畫璧嬪肩殑鏃朵警錛岄棶棰樺氨鍑虹幇浜嗭細A_class a,b,c:(a=b)=c;鍥犱負a.operator=(b)鐨勮繑鍥炲兼槸瀵筧鐨刢onst寮曠敤錛屼笉鑳藉啀灝哻璧嬪肩粰const甯擱噺銆?br />
鍥?綾繪垚鍛樺嚱鏁頒腑const鐨勪嬌鐢?br /> 涓鑸斁鍦ㄥ嚱鏁頒綋鍚庯紝褰㈠錛?br /> void fun() const;
濡傛灉涓涓垚鍛樺嚱鏁扮殑涓嶄細淇敼鏁版嵁鎴愬憳錛岄偅涔堟渶濂藉皢鍏跺0鏄庝負const錛屽洜涓篶onst鎴愬憳鍑芥暟涓笉鍏佽瀵規暟鎹垚鍛樿繘琛屼慨鏀癸紝濡傛灉淇敼錛岀紪璇戝櫒灝嗘姤閿欙紝榪欏ぇ澶ф彁楂樹簡紼嬪簭鐨勫仴澹с?br />
浜?浣跨敤const鐨勪竴浜涘緩璁?br /> 1 瑕佸ぇ鑳嗙殑浣跨敤const錛岃繖灝嗙粰浣犲甫鏉ユ棤灝界殑鐩婂錛屼絾鍓嶆彁鏄綘蹇呴』鎼炴竻妤氬師濮旓紱
2 瑕侀伩鍏嶆渶涓鑸殑璧嬪兼搷浣滈敊璇紝濡傚皢const鍙橀噺璧嬪鹼紝鍏蜂綋鍙鎬濊冮錛?br /> 3 鍦ㄥ弬鏁頒腑浣跨敤const搴旇浣跨敤寮曠敤鎴栨寚閽堬紝鑰屼笉鏄竴鑸殑瀵硅薄瀹炰緥錛屽師鍥犲悓涓婏紱
4 const鍦ㄦ垚鍛樺嚱鏁頒腑鐨勪笁縐嶇敤娉曪紙鍙傛暟銆佽繑鍥炲箋佸嚱鏁幫級瑕佸緢濂界殑浣跨敤錛?br /> 5 涓嶈杞繪槗鐨勫皢鍑芥暟鐨勮繑鍥炲肩被鍨嬪畾涓篶onst;6闄や簡閲嶈澆鎿嶄綔絎﹀涓鑸笉瑕佸皢榪斿洖鍊肩被鍨嬪畾涓哄鏌愪釜瀵硅薄鐨刢onst寮曠敤;


]]>
bcb涓殑dll璋冪敤dll渚嬪瓙http://www.tkk7.com/zhaochengming/archive/2007/11/05/158275.htmlhelloworld2008helloworld2008Mon, 05 Nov 2007 07:37:00 GMThttp://www.tkk7.com/zhaochengming/archive/2007/11/05/158275.htmlhttp://www.tkk7.com/zhaochengming/comments/158275.htmlhttp://www.tkk7.com/zhaochengming/archive/2007/11/05/158275.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/158275.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/158275.html#include <windows.h>
#include "string.h"
#include "Decode.h"

#pragma argsused
typedef int (__stdcall *fun_AddFun)(int Data);
HINSTANCE gLib = NULL;
fun_AddFun gFun = NULL;
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved){
        switch(reason) {
                case DLL_PROCESS_ATTACH: {
                        char tPath[255];
                        int tSize;
                        GetModuleFileName(hinst,tPath,255);
                        tSize = strlen(tPath)-1;
                        while(tPath[tSize]!='\\') {
                                --tSize;
                        }
                        tPath[tSize+1] = 0;
                        strcat(tPath,"Test.dll");

                        gLib = LoadLibrary(tPath);
                        if(gLib == NULL) {
                                MessageBox(NULL,tPath,"Load Library Failed",MB_OK);
                                return;
                        }
                        gFun = (fun_AddFun)GetProcAddress(gLib,"AddFun");
                }
                break;
                case DLL_PROCESS_DETACH: {
                        if(gLib) {
                                FreeLibrary(gLib);
                                gLib = NULL;
                        }
                }
                break;
        }
        return 1;
}

JNIEXPORT jint JNICALL Java_Encode_Add (JNIEnv *env, jclass cls, jint a, jint b) {
        if(gFun==NULL)
                return 0;
        else {
                int tRe = gFun(100);
                return a + b + tRe;
        }              
}

 int  __declspec(dllexport) __stdcall fun_x(int a,int b)
{
        if(gFun==NULL)
                return 0;
        else {
                int tRe = gFun(100);
                return a + b + tRe;
        }              

}

 



]]>
bcb涓垱寤簀ni鐨刣ll瑕佹敞鎰忕殑鍦版柟http://www.tkk7.com/zhaochengming/archive/2007/11/05/158258.htmlhelloworld2008helloworld2008Mon, 05 Nov 2007 06:24:00 GMThttp://www.tkk7.com/zhaochengming/archive/2007/11/05/158258.htmlhttp://www.tkk7.com/zhaochengming/comments/158258.htmlhttp://www.tkk7.com/zhaochengming/archive/2007/11/05/158258.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/158258.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/158258.html 1.鍘婚櫎欏圭洰鐨凱akcages涓殑Build with runtime packages
2.鍦↙inker閫夐」涓幓闄se dynamic RTL閫夐」
3.鍦―irectories/conditionals涓夋嫨include path娣誨姞java鐨刬nclude鍜寃in鐩綍

]]>
c璇誨啓鏂囦歡http://www.tkk7.com/zhaochengming/archive/2007/11/02/157772.htmlhelloworld2008helloworld2008Fri, 02 Nov 2007 08:15:00 GMThttp://www.tkk7.com/zhaochengming/archive/2007/11/02/157772.htmlhttp://www.tkk7.com/zhaochengming/comments/157772.htmlhttp://www.tkk7.com/zhaochengming/archive/2007/11/02/157772.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/157772.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/157772.html#include <iostream.h>
#include <cstdlib>
#include <fstream> 
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
    char* str = "e:/test/nihao.txt";
    FILE *t = fopen(str,"wb+");
    char tbuf[10]={0};
    fwrite(tbuf,1,100,t);
    fclose(t);
    system("PAUSE");
    return EXIT_SUCCESS;
}



FILE *tIn = fopen(szStr,"rb");
    if (tIn == NULL) {
       cout<<"鏂囦歡涓嶈兘鎵撳紑!";
       return NULL;
    }
    fseek(tIn, 0, SEEK_END);
    int tSize = ftell(tIn);
    fseek(tIn, 0, SEEK_SET);
    char *tBuf = new  char[tSize];
    fread(tBuf,tSize,1,tIn);
    fclose(tIn);

]]>
鐢╟puid鎸囦護璇誨彇CPU淇℃伅http://www.tkk7.com/zhaochengming/archive/2007/10/24/155600.htmlhelloworld2008helloworld2008Wed, 24 Oct 2007 07:04:00 GMThttp://www.tkk7.com/zhaochengming/archive/2007/10/24/155600.htmlhttp://www.tkk7.com/zhaochengming/comments/155600.htmlhttp://www.tkk7.com/zhaochengming/archive/2007/10/24/155600.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/155600.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/155600.html鐢╟puid鎸囦護璇誨彇CPU淇℃伅
#include <stdio.h>


int main()
{
    unsigned int eflags1, eflags2 = 0;
    unsigned int eax = 0;
    unsigned int ebx,ecx,edx;

 


    /**
     * 嫻嬭瘯CPU鏄惁鏀寔CPUID鎸囦護銆?br />      * eflags瀵勫瓨鍣ㄧ殑絎?1浣嶏紝濡傛灉紼嬪簭鍙互娓呮/璁劇疆瀹冿紝鍒欒鏄嶤PU鏀寔CPUID鎸囦護銆傚惁鍒欎笉鏀寔
     */

    /* 鍏堝彇eflags */
    asm volatile ("pushf\n\t"
              "popl %%eax"
              : "=a"(eflags1)
              :
              : "memory"
              );
    printf("original eflags is %p\n", eflags1);

    /* 鎶奺flags鐨勭21浣嶅彇鍙嶏紝鍐欏洖瀵勫瓨鍣ㄤ腑 */
    asm volatile ("pushl %0\n\t"
              "popf"
              :
              : "g"(eflags1 & ~( eflags1 & (1<<21) ) )
              );

    /* 媯鏌ヤ竴涓嬬幇鍦ㄧ殑eflags錛岀‘璁ょ21浣嶅拰鏈鍒濈殑鍊肩浉鍙?*/
    asm volatile ("pushf\n\t"
              "popl %%eax"
              : "=a"(eflags2)
              :
              : "memory"
              );
    printf("modified eflags is %p\n", eflags2);

    /* 鎶婂師鏉ョ殑eflags鍊艱緗洖鍘?*/
    asm volatile ("pushl %0\n\t"
              "popf"
              :
              : "g"(eflags1)
              );
    /**
     * FIXME: Intel鏂囨。騫舵病鏈夎錛屽鏋滀笉鏀寔CPUID鐨勮瘽錛宑lear/set eflags鐨勭21浣嶄細鏈変粈涔堥敊璇?br />      * 瀹冨彧璇達紝鍦ㄤ笉鏀寔CPUID鎸囦護鐨凜PU涓婏紝濡?0386錛屾墽琛孋PUID浼氫駭鐢焛nvalid opcode閿欒
     *
     * 鎵浠ワ紝鍦ㄨ繖閲屾垜浠笉澶勭悊 璇?鍐?eflags 絎?1姣旂壒澶辮觸鐨勬儏褰?br />      */

 

 

    /**
     *  eax == 1錛屽垯鍦╡ax涓繑鍥濬amily/Model/Stepping絳変俊鎭?br />      *  [0:3]    stepping
     *  [4:7]    model
     *  [8:11]    family
     *  [12:13]    processor type
     *  [16:19]    extended model ID
     *  [20:27]    extended family ID
     */
    asm volatile ("cpuid"
              : "=a"(eax)
              : "0"(1)
              );
    // printf("eax is %p\n", eax);

    printf("Extended Family\t: %d\n", (0xff00000 & eax) >> 20);
    printf("Extended Model\t: %d\n", (0xf0000 & eax) >> 16);
    printf("Processor type\t: %d\n", (0x3000 & eax) >> 12);
    printf("Family\t\t: %d\n", (0xf00 & eax) >> 8);
    printf("Model\t\t: %d\n", (0xf0 & eax) >> 4);
    printf("Stepping:\t: %d\n", (0xf & eax));

    printf("\n");

 

   
    /**
     * eax == 0x800000000
     * 濡傛灉CPU鏀寔Brand String錛屽垯鍦‥AX涓繑 >= 0x80000004鐨勫箋?br />      */
    asm volatile ("cpuid"
              : "=a"(eax)
              : "0"(0x80000000)
              );
    printf("Is CPU support Brand String? %s\n", eax >= 0x80000004? "yes":"no");
    printf("\n");

    /**
     * 濡傛灉鏀寔Brand String錛屽垯EAX浠?x80000002鍒?x80000004錛屾瘡嬈″1錛孋PUID鎸囦護榪斿洖錛?br />      * EAX    : Processor Brand String
     * EBX    : Processor Brand String Continued
     * ECX    : Processor Brand String Continued
     * EDX    : Processor Brand String Continued
     */

    if(eax >= 0x80000004) {
        unsigned int brands[4]; //姣忔鐨別ax銆乪bx銆乪cx銆乪dx

        unsigned int i;

        printf("Brand String\t: ");

        for (i = 0x80000002; i <= 0x80000004; i++) {
            asm volatile ("cpuid"
                      : "=a"(brands[0]), "=b"(brands[1]), "=c"(brands[2]), "=d"(brands[3])
                      : "0" (i)
                      );
            printf("%s", (char *)brands);
        }

        //FIXME: 鎵撳嚭鏉ョ殑瀛楃涓叉槸錛欼n^Htel(R) Pentium(R^H) D CPU 2.80GHz

        //鍏朵腑^H鏄釜涓嶅彲瑙佸瓧絎︼紝浼氭妸瀹冨墠涓涓悆鎺?/p>

        printf("\n");
    }

 

    /**
     * eax == 0
     * eax    : cpuid鎸囦護鍏佽鐨勬渶澶ax杈撳叆鍊?br />      * ebx    : "Genu"
     * ecx    : "ntel"
     * edx    : "inel"
     */
    asm volatile ("cpuid"
              : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
              : "0"(0) );
    printf("Maximum CPUID Input EAX : %p\n", eax);


    char string[128];
    snprintf(string, 5, "%s", (char *)&ebx);
    snprintf(string + 4, 5, "%s", (char *)&edx);
    snprintf(string + 8, 5, "%s", (char *)&ecx);
    printf("Vendor\t\t: %s\n", string);

    printf("\n");


    /**
     * eax == 1,
     * edx鐨勭18姣旂壒涓?錛屽垯CPU鏀寔serial number
     *         涓?錛屽垯涓嶆敮鎸侊紝鎴栬呰disabled
     * 搴忓垪鍙鋒湁96浣嶏紝鍏朵腑鏈楂?2浣嶅嵆鏄痚ax鐨勮緭鍑哄箋傚簲褰撴妸瀹冧繚瀛樹笅鏉ワ紝鐒跺悗
     * 鍐嶈緗甧ax==3, 鍙栧墿涓嬬殑64浣?br />      */
    asm volatile ("cpuid"
              : "=a"(eax), "=d"(edx)
              : "a"(1)
              );
    if ( edx & (1 << 18) ) {
        /* serial number supported */
        /* edx杈撳嚭涓棿32浣嶇殑搴忓垪鍙鳳紝ecx杈撳嚭鏈浣?2浣嶇殑搴忓垪鍙?*/
        asm volatile ("cpuid"
                  : "=c"(ecx), "=d"(edx)
                  : "a"(3)
                  );
        printf("Serial Number\t : %x-%x-%x-%x-%x-%x\n",
                eax >> 16, eax << 16, edx >> 16, edx << 16, ecx >> 16, ecx << 16);
    } else
        printf("Serial Number not supported.\n");

    printf("\n");


    /**
     * eax == 80000006h錛岃繑鍥濴2 Cache鐨勪俊鎭?br />      *
     * ecx[31:16]    : L2 Cache size, in Kbytes
     * ecx[15:12]    : L2 Cache Associativity
     *           00h disabled
     *           01h direct mapped
     *           02h 2-Way
     *           04h 4-Way
     *           06h 8-Way
     *           08h 16-Way
     *           0Fh Fully associative
     * ecx[7:0]    : L2 Cache Line size in bytes
     */
    asm volatile ("cpuid"
              : "=c"(ecx)
              : "a"(0x80000006)
              );
    printf("L2 Cache Size\t : %dKbytes\n", ( ecx >> 16 ) );
    printf("L2 Cache Line Size\t : %dbytes\n", (ecx & 0xff));

    printf("L2 Cache Associativity\t : ");
    switch ( (ecx & 0xf000) >> 12 )
    {
        case 0x00:
            printf("%s\n", "disabled");
            break;
        case 0x01:
            printf("%s\n", "direct mapped");
            break;
        case 0x02:
            printf("%s\n", "2-Way");
            break;
        case 0x04:
            printf("%s\n", "4-Way");
            break;
        case 0x06:
            printf("%s\n", "8-Way");
            break;
        case 0x08:
            printf("%s\n", "16-Way");
            break;
        case 0x0f:
            printf("Fully associative");
            break;
        default:
            printf("No such entry...\n");
    }

    printf("\n");


    /**
     * Input : eax == 4 && ecx == 0
     *
     * (eax[31:26] + 1) 鏄鐗╃悊澶勭悊鍣╬ackage涓婂疄鐜扮殑core CPUs鏁扮洰
     */
    asm volatile ("cpuid"
              : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
              : "0"(4), "2"(0)
              );
    printf("Number of Cores on this physical package\t : %d\n", (eax >> 27) + 1 );

    printf("\n");


    /**
     * Input : eax == 1錛屽垯edx榪斿洖feature flag
     *
     */

 

 

    return 0;
}



]]>
Linux鏌ョ湅緗戝崱machttp://www.tkk7.com/zhaochengming/archive/2007/10/24/155599.htmlhelloworld2008helloworld2008Wed, 24 Oct 2007 07:01:00 GMThttp://www.tkk7.com/zhaochengming/archive/2007/10/24/155599.htmlhttp://www.tkk7.com/zhaochengming/comments/155599.htmlhttp://www.tkk7.com/zhaochengming/archive/2007/10/24/155599.html#Feedback0http://www.tkk7.com/zhaochengming/comments/commentRss/155599.htmlhttp://www.tkk7.com/zhaochengming/services/trackbacks/155599.html#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <net/if.h>
#include <string.h>

int main(int argc, char *argv[]){
        struct ifreq ifreq;
        int sock;

        if(argc!=2)
        {
                printf("Usage : ethname\n");
                return 1;
        }
        if((sock=socket(AF_INET,SOCK_STREAM,0))<0)
        {
                perror("socket");
                return 2;
        }
        strcpy(ifreq.ifr_name,argv[1]);
        if(ioctl(sock,SIOCGIFHWADDR,&ifreq)<0)
        {
                perror("ioctl");
                return 3;
        }
        printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[0],
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[1],
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[2],
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[3],
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[4],
                        (unsigned char)ifreq.ifr_hwaddr.sa_data[5]);
        unsigned char temp = (unsigned char)ifreq.ifr_hwaddr.sa_data[0];
        int a = temp;
        printf("%02x",a);
        return 0;
}



]]>
主站蜘蛛池模板: 亚洲国产精品日韩在线观看| 亚洲综合自拍成人| 亚洲AV无码一区二区乱子伦| 99久久亚洲精品无码毛片| 亚洲国产精品免费在线观看| 亚洲精品自偷自拍无码| 免费一区二区无码视频在线播放 | 亚洲欧洲日产国码久在线观看| 亚洲精品在线播放视频| 亚洲成a人片在线观看天堂无码| 又长又大又粗又硬3p免费视频| 日韩免费观看一区| 成年性生交大片免费看| 浮力影院亚洲国产第一页| 亚洲高清资源在线观看| 综合偷自拍亚洲乱中文字幕| a毛片免费全部在线播放** | 日本免费中文字幕| 大学生一级特黄的免费大片视频| 国产91精品一区二区麻豆亚洲 | 亚洲AV无码XXX麻豆艾秋| 国产免费久久精品丫丫| 69式国产真人免费视频 | 在线精品免费视频| 亚洲熟妇无码AV在线播放| 亚洲人成777在线播放| 一级毛片a免费播放王色电影| 91青青国产在线观看免费| 国产在线19禁免费观看| 亚洲精品人成在线观看| 亚洲AV成人无码久久WWW| 热re99久久6国产精品免费| 国产免费爽爽视频免费可以看| 亚洲国产精品久久久久网站 | 国产精品亚洲综合久久| 热久久这里是精品6免费观看| 成人毛片免费播放| 亚洲制服中文字幕第一区| 免费观看四虎精品成人| 久久国内免费视频| 亚洲国产精品VA在线看黑人 |