锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久SS麻豆欧美国产日韩,久久97精品久久久久久久不卡,久久精品国产亚洲精品2020http://www.shnenglu.com/k71983/鎴戠煡閬撳茍涓嶆槸 鎵鏈夐笩鍎塊兘椋炵繑 zh-cnWed, 07 May 2025 19:59:02 GMTWed, 07 May 2025 19:59:02 GMT60鎼浜嗭紝鍛靛懙 http://www.cnblogs.com/k7_1983/http://www.shnenglu.com/k71983/archive/2008/09/25/62768.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Thu, 25 Sep 2008 08:35:00 GMThttp://www.shnenglu.com/k71983/archive/2008/09/25/62768.htmlhttp://www.shnenglu.com/k71983/comments/62768.htmlhttp://www.shnenglu.com/k71983/archive/2008/09/25/62768.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/62768.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/62768.htmlhttp://www.cnblogs.com/k7_1983/ 鍗氬鍥湁灝忕粍錛屾洿濂戒氦嫻侊紒^_^

]]>
緲昏瘧-C++鏈綆鍗曠殑windows紼嬪簭 The Simplest Windows Programhttp://www.shnenglu.com/k71983/archive/2008/09/23/62560.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Tue, 23 Sep 2008 03:01:00 GMThttp://www.shnenglu.com/k71983/archive/2008/09/23/62560.htmlhttp://www.shnenglu.com/k71983/comments/62560.htmlhttp://www.shnenglu.com/k71983/archive/2008/09/23/62560.html#Feedback4http://www.shnenglu.com/k71983/comments/commentRss/62560.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/62560.html 鏉ヨ嚜錛歨ttp://www.relisoft.com/win32/winnie.html
璇戯細鑱傚厓鏈?
1. The Simplest Windows Program
1.鏈綆鍗曠殑Windows紼嬪簭

Before you can even begin thinking about programming in Windows, you have to be able to understand how this simple program works.

鍦ㄤ綘寮濮嬫兂濡備綍鍦╳indows涓嬬紪紼嬩箣鍓嶏紝浣犲繀欏昏寮勬竻妤氫笅闈㈣繖涓畝鍗晈indows紼嬪簭鐨勫伐浣滃師鐞嗐?

Windows API calls are highlighted in blue and Windows specific data types are shown in green. I will also usually put a double colon in front of API calls. In C++, that simply means that I'm calling a global function, in case there is some ambiguity.

鎴戠敤钃濊壊鏉ユ爣璇哤indows鐨凙PI璋冪敤錛岀敤緇胯壊鏉ユ爣璇哤indows涓殑鐗規畩鐨勬暟鎹被鍨嬨傚悓鏃舵垜鍦ˋPI鍑芥暟鐨勫墠闈㈡斁緗簡涓瀵瑰啋鍙?:銆傚湪C++涓紝榪欏鍐掑彿灝辨槸鍛婅瘔緙栬瘧鍣ㄦ垜鍦ㄨ皟鐢ㄤ竴涓叏灞鍑芥暟銆傜敱浜庢湁鏃跺欐湁鍚屽悕鐨勫嚱鏁幫紝涓轟簡涓嶅紩璧鋒販娣嗭紝鍦ㄥ墠闈㈡斁緗啋鍙鋒槸涓縐嶅緢濂界殑鍋氭硶

Sources (zipped file 4k) are right here. Remember to compile them as a Windows application. For instance, in Visual C++ select File.New.Projects.Win32 Application. Otherwise you'll get the error: unresolved external _main. (I provided project file Winnie.dsp for those of you who use MS VC++ 6.0 and Winnie.sln for the users of VC++ 7.0)

鎴戞彁渚涗簡婧愪唬鐮?涓涓?k澶у皬鐨勫帇緙╂枃浠?銆傝璁頒綇瑕佹妸瀹冧滑緙栬瘧鎴愪竴涓獁indows搴旂敤紼嬪簭鑰屼笉鏄痺indows鎺у埗鍙扮▼搴忋傚惁鍒欙紝浣犲氨浼氬緱鍒版壘涓嶅埌main鍑芥暟鐨勯敊璇傚湪VC++6.0涓紝鎴戜滑鍙互閫氳繃閫夋嫨File鈥斺擭ew Projects鈥斺擶in32 Application鏉ュ垱寤轟竴涓獁indows搴旂敤紼嬪簭鐨勫伐紼嬨傚綋鐒訛紝浣犵敤涓嶇潃榪欎箞鎷呭績錛屾垜宸茬粡鎻愪緵浜嗕袱涓仛濂界殑宸ョ▼鏂囦歡緇欎綘銆備竴涓槸winnie.dsp錛屼綘鍙互鍦╒C++6.0涓嬩嬌鐢ㄣ備竴涓槸Winnie.sln錛屼綘鍙互鍦╒C++7.0涓嬩嬌鐢ㄣ?

First, in a Windows program, you have to define a Window Class, the "class" of window(s) that will be displayed by your application (not a C++ class). In our case we will display only one window, but still, we need to give Windows some minimal information about its Class. The most important part of the WinClass (now, that's a C++ class that describes the Window Class) is the address of the callback procedure, or the Window Procedure. Windows is supposed to call us--Windows sends messages to our program by calling this procedure.

濂戒簡錛岃鎴戜滑鏉ョ湅鐪嬪浣曞啓榪欎釜鏈綆鍗曠殑紼嬪簭鍚с傞鍏堬紝鍦ㄤ竴涓獁indows紼嬪簭閲岄潰錛屼綘闇瑕佸畾涔変竴涓獥鍙g被錛屾敞鎰忚繖涓被鐨勬蹇典笉鍚屼簬C++涓殑綾伙紝榪欎釜紿楀彛綾葷浉褰撲簬C璇█涓殑緇撴瀯浣擄紝浣犳妸榪欎釜緇撴瀯浣撳~濂戒簡錛岀劧鍚庝綘鐨勫簲鐢ㄧ▼搴忓氨浼氭牴鎹綘濉殑榪欎簺淇℃伅鏉ユ樉紺虹獥鍙c傚湪鎴戜滑鐨勪緥瀛愰噷闈紝鎴戜滑浠呬粎鏄劇ず涓涓獥鍙c備絾鏄氨綆楁槸榪欐牱錛屾垜浠篃蹇呴』瑕佺粰鎴戜滑鐨勭獥鍙f渶灝戠殑紿楀彛綾諱俊鎭傝屽叾涓渶閲嶈鐨勯儴鍒嗗氨鏄洖璋冨嚱鏁頒簡錛屾湁鏃跺欐垜浠篃縐板畠涓虹獥鍙h繃紼嬨傚叾瀹炶繖鏄竴涓嚱鏁版寚閽堬紝姣忔紼嬪簭闇瑕佸鐞嗘秷鎭殑鏃跺欙紝windows灝遍氳繃榪欎釜鍑芥暟鎸囬拡鏉ヨ皟鐢ㄦ垜浠啓濂界殑鍥炶皟鍑芥暟銆傛槸鐨勶紝浣犵湅鍒幫紝鏄痺indows璋冪敤鎴戜滑緙栧啓鐨勫嚱鏁般備綘榪樿寰楀嚱鏁版寚閽堝悧錛熷鏋滀笉鏄緢娓呮錛屽彲浠oogle涓涓嬶紝o(∩_∩)o…

Notice the declaration of WindowProcedure. Windows calls it with a handle to the window in question, the message, and two data items associated with the message, the paramters, WPARAM and LPARAM.

璁╂垜浠湅鐪媁indowProcedure(紿楀彛榪囩▼銆佸洖璋冨嚱鏁?鐨勫畾涔夈備粩緇嗙湅涓涓嬶紝絎竴涓嚱鏁版槸涓涓彞鏌勶紝涔熷氨鏄釜鏁存暟銆俉indows鐢ㄥ畠鏉ュ尯鍒槸鍝釜紿楀彛銆傜劧鍚庢槸娑堟伅錛岀劧鍚庢槸涓庢秷鎭叧緋誨瘑鍒囩殑涓や釜鍙傛暟WPARAM鍜孡PARAM銆傝繖涓垜鏈潵鎯寵涓涓嬶紝鐣欏埌浠ュ悗鍚э紝姣曠珶鍘熸枃涓湪榪欓噷娌℃湁璁層?

In WinClass we also have to specify things like the program instance handle HINSTANCE, the mouse cursor (we just load the standard arrow cursor), the brush to paint the window's background (we chose the default window color brush), and the symbolic name of our class (you don't have to understand the meaning of all those yet).

鍦ㄤ笅闈㈢殑WinClass綾諱腑鎴戜滑蹇呴』緇欎竴浜涚獥鍙g被鐨勫瓧孌佃祴鍊鹼紝濡傜獥鍙g殑瀹炰緥鍙ユ焺HINSTACE,榧犳爣鍏夋爣(鎴戜滑浠呬粎鍔犺澆浜嗘爣鍑嗙殑綆ご榧犳爣)錛岀敾紿楀彛鑳屾櫙鐨勭敾鍒?鎴戜滑鐢ㄧ殑鏄獥鍙g己鐪佺殑鑳屾櫙棰滆壊鐢誨埛)錛屾渶鍚庤繕鏈夌獥鍙g被鐨勫悕瀛?紿楀彛綾葷殑鍚嶅瓧鏈濂藉拰鍒漢鐨勪笉鍚?.(褰撶劧錛岀幇鍦ㄤ綘涓嶉渶瑕佸紕鏄庣櫧榪欎簺鍙傛暟鐨勬剰涔?

Once all the fields of WNDCLASS are filled, we register the class with the Windows system.

涓鏃︽垜浠妸WNDCLASS緇撴瀯浣撳~瀹屼簡錛屾垜浠氨閫氳繃璋冪敤RegisterClass鍑芥暟鍦╳indows緋葷粺涓敞鍐屾垜浠殑紿楀彛綾匯傚ソ浜嗭紝鍏堢湅鐪嬫垜鏄庢牱灝佽WNDCLASS鍒頒竴涓猈inClass綾諱腑鍘葷殑銆?

#include <windows.h>
LRESULT CALLBACK WindowProcedure
    (HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);
class WinClass
{
public:
    WinClass (WNDPROC winProc, char const * className, HINSTANCE hInst);
    void Register ()
    {
        ::RegisterClass (&_class);//now we don’t deal with the error
    }//we will process the error in the next version
private:
    WNDCLASS _class;//define a private WNDCLASS object member
};

WinClass::WinClass
    (WNDPROC winProc, char const * className, HINSTANCE hInst)
{
    _class.style = 0;
    _class.lpfnWndProc = winProc; // window procedure: mandatory
    _class.cbClsExtra = 0;
    _class.cbWndExtra = 0;
    _class.hInstance = hInst;         // owner of the class: mandatory
    _class.hIcon = 0;
    _class.hCursor = ::LoadCursor (0, IDC_ARROW); // optional
    _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // optional
    _class.lpszMenuName = 0;
    _class.lpszClassName = className; // mandatory
}
Once the Window Class is registered, we can proceed with the creation of a window. This is done by calling the CreateWindow API. It takes a lot of arguments: the name of the window class that we have just registered, the caption that will appear in the title bar, window style, position, size, and the application instance. The rest of the arguments, for the time being, will be left equal to zero.

涓鏃︾獥鍙g被娉ㄥ唽鎴愬姛錛屾垜浠氨鍙互鐢ㄥ畠鏉ュ垱寤轟竴涓獥鍙c傛垜浠氳繃璋冪敤CreateWindow榪欎釜API鍑芥暟鏉ュ畬鎴愬畠銆傚畠鏈夊緢澶氬弬鏁幫紝榪欏彲鑳借浣犳湁鐐圭儲錛屼笉榪囦笉瑕佽繘錛屼綘鍙鍐欎竴嬈″氨濂戒簡銆傝繖浜涘弬鏁板寘鎷細鎴戜滑鍒氬垰娉ㄥ唽濂界殑紿楀彛綾葷殑鍚嶅瓧(榪欎釜瑕佹槸鎼為敊浜嗭紝浣犵殑紿楀彛鍙兘灝卞嚭涓嶆潵浜?,鎴戜滑紿楀彛鐨勬爣棰樻爮涓婄殑鏍囬錛岀獥鍙g殑鏍峰紡錛屼綅緗紝澶у皬榪樻湁搴旂敤紼嬪簭鐨勫疄渚嬪彞鏌勩傚墿涓嬬殑鍙傛暟鏆傛椂鎴戜滑榪樹笉闇瑕佺敤鍒幫紝鎴戜滑鎶婂畠浠垵濮嬪寲涓?銆?

This part of the program can also be encapsulated into a C++ class, WinMaker.

紼嬪簭鐨勮繖閮ㄥ垎涔熻鎴戝皝瑁呭埌浜嗕竴涓狢++鐨勭被WinMaker褰撲腑銆?

The window will not appear on the screen until you tell Windows to show it.

灝辯畻浣犲垱寤哄ソ浜嗙獥鍙o紝浣嗕綘榪樻槸鐪嬩笉鍒幫紝浣犲繀欏昏皟鐢⊿howWindow鍑芥暟璁╁畠鏄劇ず銆?
class WinMaker
{
public:
    WinMaker (): _hwnd (0) {}
    WinMaker (char const * caption, 
              char const * className,
              HINSTANCE hInstance);
    void Show (int cmdShow)
    {
        ::ShowWindow (_hwnd, cmdShow);
        ::UpdateWindow (_hwnd);
    }
protected:
    HWND _hwnd;
};
WinMaker::WinMaker (char const * caption, 
                    char const * className,
                    HINSTANCE hInstance)
{
    _hwnd = ::CreateWindow (
        className,            // name of a registered window class
        caption,              // window caption
        WS_OVERLAPPEDWINDOW,  // window style
        CW_USEDEFAULT,        // x position
        CW_USEDEFAULT,        // y position
        CW_USEDEFAULT,        // witdh
        CW_USEDEFAULT,        // height
        0,                    // handle to parent window
        0,                    // handle to menu
        hInstance,            // application instance
        0);                   // window creation data
}
A Windows program is event-driven. It means that you, as a programmer, are supposed to be on the defensive. The user will bombard Windows with various input actions, and Windows will bombard your program with messages corresponding to these actions. All you have to do is to respond to these messages. The picture below shows schematically how it works.

Windows紼嬪簭鏄簨浠墮┍鍔ㄧ殑銆傝繖灝辨槸璇翠綘浣滀負涓涓獁indows紼嬪簭鍛橈紝鎵鍋氱殑搴旇鏄槻寰″紡緙栫▼銆傚叾瀹炰篃娌℃湁榪欎箞涓ラ噸銆傚叿浣撴潵璇村氨鏄紝鐢ㄦ埛浼氬彂緇檞indows澶氱杈撳叆琛屼負錛岃寃indows鎶婅繖浜涜緭鍏ョ敤娑堟伅鐨勬柟寮忓彂緇欎綘鐨勭▼搴忋傝屼綘錛屾墍鍋氱殑灝辨槸閽堝姣忎竴涓秷鎭湪鍥炶皟鍑芥暟涓仛鍑哄鐞嗐備笅闈㈢殑榪欏紶鍥劇ず鎰忔х殑璇存槑浜嗚繖涓繃紼嬨傚浘鍦ㄤ笅涓欏電殑涓嬩竴欏碉紝o(∩_∩)o…

Windows gets various events from the keyboard, the mouse, the ports, etc. Each event is quickly converted into a message. Windows (the operating system) dispatches messages to appropriate windows. For instance, all keyboard messages go to the window that currently has the input focus (the active window). Mouse messages are dispatched according to the position of the mouse cursor. They usually go to the window that is directly under the cursor (unless some program captured the mouse).

棣栧厛,windows緋葷粺浠庨敭鐩樸侀紶鏍囥佺鍙g瓑絳夊悇縐嶈澶囦腑鑾峰緱鍚勭浜嬩歡銆傛瘡涓簨浠惰蹇熺殑杞崲涓烘秷鎭俉indows鍒嗘淳榪欎簺娑堟伅緇欏悎閫傜殑紿楀彛銆備婦涓緥瀛愶紝鎵鏈夌殑閿洏娑堟伅閮戒細浼犵粰褰撳墠鍏鋒湁杈撳叆鐒︾偣鐨勭獥鍙?涔熷氨鏄墍璋撶殑媧誨姩紿楀彛)銆傞紶鏍囨秷鎭垯浼氭牴鎹紶鏍囧厜鏍囨墍鍦ㄧ殑浣嶇疆鍒嗘淳緇欑浉搴旂殑紿楀彛銆傝繖浜涚獥鍙i氬父鏄洿鎺ヤ綅浜庡厜鏍囦笅鐨勭涓涓獥鍙?闄ら潪鏈夋煇浜涚▼搴忔崟鑾烽紶鏍囨秷鎭?銆?

All these messages end up in message queues. Windows keeps a message queue for every running application (actually, for every thread). It is your duty to retrieve these messages one-by-one in what is called a message loop. Your program has to call GetMessage to retrieve a message. Then you call DispatchMessage to give it back to Windows. Couldn't Windows just go ahead and dispatch all these messages itself? In principle it could, but a message loop gives your program a chance to have a peek at them and maybe perform some additional actions before dispatching them. Or not...

鎵鏈夌殑娑堟伅閮芥斁鍦ㄦ秷鎭槦鍒楅噷闈€俉indows涓烘瘡涓涓繍琛岀殑搴旂敤紼嬪簭緇存姢涓涓秷鎭槦鍒?瀹為檯涓婏紝鏄負姣忎竴涓嚎紼?銆傛妸榪欎簺娑堟伅涓涓釜鐨勫彇鍑烘潵錛岃繖鏄綘鐨勮矗浠匯傞氬父鎴戜滑鎶婅繖孌典唬鐮佸彨鍋氭秷鎭驚鐜傚湪浣犵殑紼嬪簭閲岋紝棣栧厛璋冪敤GetMessage鍑芥暟鍙栧嚭涓鏉℃秷鎭紝鐒跺悗璋冪敤DispatchMessage鎶婂畠榪斿洖緇橶indows銆俉indows榪樹細閲嶆柊鍒嗘淳榪欎簺娑堟伅鍚?鍘熷垯涓婁笉浼氾紝浣嗘槸浣犲彲浠ュ湪娑堟伅寰幆涓嬌鐢≒eekMessage鍑芥暟鏉ユ煡鐪嬫秷鎭屼笉鍒嗘淳瀹冿紝鍥犱負鏌愪簺鎯呭喌涓嬶紝浣犻渶瑕佸湪鍒嗘淳榪欎簺娑堟伅涔嬪墠鍋氫竴浜涢澶栫殑宸ヤ綔銆?

Each message is addressed to a particular window. When you tell Windows to dispatch such a message, it will figure out the class of this window, find the associated Window Procedure, and call it. Every single message sent to our window will end up in our window procedure. It is now up to us to respond to it. So, do we have to respond appropriately to every possible type of Windows message? There a hundreds of them! Fortunately, no! We only need to intercept those messages that we are interested in. Everything else we pass back to Windows for default processing using DefWindowProc.

姣忎釜娑堟伅琚紶閫掑埌涓涓壒孌婄殑紿楀彛銆傚綋浣犲憡璇墂indows鍒嗘淳涓鏉′俊鎭殑鏃跺欙紝windows浼氬厛鎵懼嚭榪欎釜紿楀彛鐨勭被錛岀劧鍚庢壘鍒頒笌涔嬪叧鑱旂殑紿楀彛榪囩▼錛屾渶鍚庤皟鐢ㄨ繖涓獥鍙h繃紼嬨傛瘡涓彂閫佸埌鎴戜滑紿楀彛鐨勬秷鎭兘浼氬湪鎴戜滑鐨勭獥鍙h繃紼嬩腑緇堟銆傜幇鍦ㄨ疆鍒版垜浠潵澶勭悊榪欎簺娑堟伅浜嗐傚洜姝わ紝鎴戜滑蹇呴』瑕佸鐞嗘墍鏈夌殑娑堟伅綾誨瀷錛熶笉錛岃繖閲屾湁鍑犵櫨縐嶆秷鎭紝鎴戜滑鍙渶瑕佸鐞嗗鎴戜滑鏈夌敤鐨勬秷鎭氨鍙互浜嗐備絾鍏跺畠娑堟伅鎬庝箞鍔炲憿錛熶笉鐢ㄦ媴蹇冿紝鍏跺畠娑堟伅鎴戜滑閫氳繃璋冪敤DefWindowProc榪欎釜鍑芥暟鏉ヨ嚜鍔ㄥ鐞嗐?

Let's have a look at WinMain. The execution of a Windows program doesn't start in main--it starts in WinMain. In our WinMain, we create a WinClass and register it. Then we create an actual window (of the class we've just registered) and show it. Actually, WinMain is called with the appropriate show directive--the user might want to start the application minimized or maximized. So we just follow this directive. Next, we enter the message loop and keep retrieving and dispatching messages until GetMessage returns 0. At that point the message's wParam will contain the return code of the whole program.

璁╂垜浠湅鐪媁inMain榪欎釜鍑芥暟銆備竴涓獁indows鍑芥暟鐨勫紑濮嬩笉鏄痬ain鍑芥暟錛岃屾槸WinMain銆傚湪鎴戜滑鐨剋inMain鍑芥暟閲岋紝鎴戜滑鍒涘緩浜嗕竴涓猈inClass鐨勫璞inClass錛岀劧鍚庢垜浠湪windows涓敞鍐屼簡瀹冦傛帴涓嬫潵鎴戜滑鍒涘緩浜嗕竴涓獥鍙?鎴戜滑鍒氬垰娉ㄥ唽鐨勭獥鍙g被鎵瀵瑰簲鐨勭獥鍙?騫朵笖鏄劇ず瀹冦傚疄闄呬笂錛學inMain鐢變竴涓弬鏁版槸鐢ㄦ潵鎸囨槑紿楀彛鏄劇ず鏁堟灉鐨?榪欐牱錛岀敤鎴峰彲浠ユ寚瀹氱獥鍙f樉紺虹殑鏂瑰紡)鈥斺旂敤鎴峰彲鑳藉笇鏈涙墦寮榪欎釜紼嬪簭鐢ㄦ渶灝忓寲鎴栬呮渶澶у寲鐨勬柟寮忔墦寮錛屽洜姝わ紝鎴戜滑鍦ㄨ繖閲屽彧闇瑕佺洿鎺ヤ嬌鐢ㄨ繖涓弬鏁板氨鍙互浜嗐傜劧鍚庢垜浠繘鍏ユ秷鎭驚鐜茍涓嶆柇鍙栧嚭娑堟伅鍜岃繘琛屽垎媧撅紝鐩村埌GetMessage鍑芥暟榪斿洖0銆傝繖涓椂鍊欐秷鎭殑wParam鍙傛暟灝嗕細鍖呭惈鏁翠釜紼嬪簭鐨勮繑鍥炲箋?
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
                    char * cmdParam, int cmdShow)
{
    char className [] = "Winnie";
    WinClass winClass (WindowProcedure, className, hInst);
    winClass.Register ();
    WinMaker win ("Hello Windows!", className, hInst);
    win.Show (cmdShow);
    
MSG msg; int status; while ((status = ::GetMessage (& msg, 0, 0, 0)) != 0) { if (status == -1) return -1; ::DispatchMessage (& msg); }
return msg.wParam; }
The GetMessage API is an interesting example of the bizarre Microsoft Troolean (as opposed to traditional, Boolean) logic. GetMessage is defined to return a BOOL, but the documentation specifies three types of returns, non-zero, zero and -1. I am not making it up! Here's an excerpt from the help file:

GetMessage鍑芥暟鏄竴涓緢濂界瑧鐨勫井杞殑涓夊煎竷灝旂被鍨嬬殑渚嬪瓙銆侴etMessage鍑芥暟瀹氫箟鐨勮繑鍥炲兼槸BOOL綾誨瀷錛屼絾鏄枃妗e嵈鏄庣‘鎸囧嚭瀹冨惈鏈変笁縐嶈繑鍥炲鹼紝闈?銆?鍜?1銆傛垜涓嶆兂鍦ㄨ繖閲屽璐瑰彛鑸屻備笅闈㈡槸浠嶮SDN涓殑鎽樺綍銆?

· If the function retrieves a message other than WM_QUIT, the return value is nonzero.
· If the function retrieves the WM_QUIT message, the return value is zero.
· If there is an error, the return value is -1.


The other important part of every Windows program is the Windows Procedure. Remember, Windows will call it with all kinds of messages. All these messages can be ignored by sending them to DefWindowProc. There is only one message that we must intercept. That's the WM_DESTROY message that is sent by Windows when the user decides to close the window (by pressing the close button in the title bar). The standard response to WM_DESTROY is to post the quit message and return zero. That's all there is to it.

璁╂垜浠湅鐪嬫墍鏈墂indows紼嬪簭閮藉緢閲嶈鐨勫洖璋冨嚱鏁板惂銆備綘闇瑕佹敞鎰忕殑鏄紝windows灝嗕負鎵鏈夌殑娑堟伅璋冪敤榪欎釜鍑芥暟銆傛墍浠ュ墿浣欑殑娑堟伅涓瀹氳閫佺粰DefWindowProc鍘誨鐞嗐傚湪榪欓噷鎴戜滑鍙鐞嗕簡涓涓秷鎭傞偅灝辨槸WM_DESTROY銆傚綋鐢ㄦ埛瑕佸叧闂竴涓獥鍙g殑鏃跺欙紝windows浼氬彂閫佽繖涓秷鎭傛爣鍑嗙殑澶勭悊WM_DESTROY娑堟伅鏄彂閫佷竴鏉¢鍑烘秷鎭紝騫惰繑鍥?銆傚ソ浜嗭紝榪欏氨鏄垜浠璁茬殑鍏ㄩ儴浜嗐?_*

// Window Procedure called by Windows
LRESULT CALLBACK WindowProcedure
    (HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_DESTROY:
            ::PostQuitMessage (0);
            return 0;
    }
    return ::DefWindowProc (hwnd, message, wParam, lParam );
}


]]>
涔︿笂鐨勭粌涔?闅忔満鏁?榫熷厰璧涜窇http://www.shnenglu.com/k71983/archive/2008/05/25/51026.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Sun, 25 May 2008 05:56:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/25/51026.htmlhttp://www.shnenglu.com/k71983/comments/51026.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/25/51026.html#Feedback1http://www.shnenglu.com/k71983/comments/commentRss/51026.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/51026.html涔︿笂鐨勪竴涓粌涔狅紒

// date 2008.5.25
// author fanghua.nie
// just do a exercise in the C How To Program
 
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
 
#define START_POS 1
#define RACE_DISTANCE  70  // the distances of the race
 
#define TORTOISE 'T'    // the symbol that is printed  in the screen as a tortoise
#define RABBIT 'R'      // the symbol that is printed in the screen as a rabbit
#define ROAD '.'        // the symbol that is printed in the screen as a mile road.
#define COMPLETE_ROAD '+'
 
// define the console color
#define LIGHT_GREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define LIGHT_YELLOW FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define LIGHT_RED FOREGROUND_RED | FOREGROUND_INTENSITY
// define BOOL datatype
typedef int BOOL;
#define TRUE 1   
#define FALSE 0
 
 
 
//get the speed of the tortoise or the rabbit
int GetTortoiseSpeed ( int percent, int * speed );
int GetRabbitSpeed ( int percent, int * speed );
 
//output the result in console interface
void PrintRaceResult ( int tortoisePosition, int rabbitPosition );
 
int main (void)
{
    
int percent; // save the percent as a integer that less 10
                
// 1  10%,   2 20%, 9 90%, 10 100% etc.
    
int speed; // save the speed of the rabbit or the tortoise
    
    
int tortoisePosition = START_POS;
    
int rabbitPosition = START_POS;
 
    
srand ( time(NULL) );
 
    
printf ("     The game began:\n");
    
//show the tortoise and the rabbit
    
PrintRaceResult ( tortoisePosition, rabbitPosition );
 
    
while ( rabbitPosition < RACE_DISTANCE && tortoisePosition < RACE_DISTANCE )
    
{
        
//compute next speed of the tortoise
        
percent = rand()%10 + 1;
 
        
if ( !GetTortoiseSpeed ( percent, &speed ) ) //get the speed of the tortoise
        
{
            
puts ("Error!\n");
            
exit (ERROR);
        
}
        
        
// move the tortoise to next position
        
tortoisePosition = tortoisePosition + speed;
 
        
if ( tortoisePosition < 0 )
            
tortoisePosition = START_POS;
        
else if ( tortoisePosition > RACE_DISTANCE )
            
tortoisePosition = RACE_DISTANCE;
        
        
//compute next rate of rabbit speed
        
percent = rand()%10 + 1; //get the percent
 
        
if ( !GetRabbitSpeed (percent, &speed) ) //get the speed of rabbit
        
{
            
puts ("Error!\n");
            
exit (ERROR);
        
}
        
        
//move the rabbit
        
rabbitPosition = rabbitPosition + speed;
        
        
//check the position whether is right or not, then correct it.
        
if ( rabbitPosition < 0 )
            
rabbitPosition = START_POS;
        
else if ( rabbitPosition > RACE_DISTANCE )
            
rabbitPosition = RACE_DISTANCE;
        
        
//show the tortoise and the rabbit
        
PrintRaceResult ( tortoisePosition, rabbitPosition );
 
    
}
    
    
//print the race result
    
if ( rabbitPosition > tortoisePosition )
    
{
        
printf ("Rabbit Wins!\n");
    
}
    
else if ( rabbitPosition == tortoisePosition )
    
{
        
printf ("It's a tie\n");
    
}
    
else
    
{
        
printf ("Tortoise Wins!\n");
    
}
 
    
return 0;
}
 
BOOL GetTortoiseSpeed ( int percent, int * speed )
{
    
if ( percent >= 1 && percent <= 5 )
    
{
        
(*speed) = 3;
        
return TRUE;
    
}
    
else if ( percent >= 6 && percent <= 7 )
    
{
        
(*speed) = -6;
        
return TRUE;
    
}
    
else if ( percent >= 8 && percent <= 10 )
    
{
        
(*speed) = 1;
        
return TRUE;
    
}
    
else
    
{
        
return FALSE;
    
}
}
 
BOOL GetRabbitSpeed ( int percent, int * speed )
{
    
if ( percent >= 1 && percent <= 2 )
    
{
        
(*speed) = 0;
        
return TRUE;
    
}
    
else if ( percent >= 3 && percent <= 4 )
    
{
        
(*speed) = 9;
        
return TRUE;
    
}
    
else if ( percent == 5 )
    
{
        
(*speed) = -12;
        
return TRUE;
    
}
    
else if ( percent >= 6 && percent <= 8 )
    
{
        
(*speed) = 1;
        
return TRUE;
    
}
    
else if ( percent >= 9 && percent <= 10 )
    
{
        
(*speed) = -2;
        
return TRUE;
    
}
    
else
    
{
        
return FALSE;
    
}
}
 
void PrintRaceResult ( int tortoisePosition, int rabbitPosition )
{
    
int tcount;
    
int rcount;
 
    
HANDLE hOut;
    
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
printf ("\n     ");
    
for ( tcount = START_POS; tcount <= RACE_DISTANCE; tcount++ )
    
{
 
        
if ( tcount == tortoisePosition )
        
{
            
SetConsoleTextAttribute (hOut, LIGHT_GREEN );
            
putchar (TORTOISE);
        
}
        
else if ( tcount < tortoisePosition )
        
{
            
SetConsoleTextAttribute (hOut, LIGHT_GREEN );
            
putchar (COMPLETE_ROAD);
        
}
        
else
        
{
            
SetConsoleTextAttribute (hOut, LIGHT_RED );
            
putchar (ROAD);
        
}
    
}
    
printf ("\n     ");
 
    
for ( rcount = START_POS; rcount <= RACE_DISTANCE; rcount++ )
    
{
        
if ( rcount == rabbitPosition )
        
{
            
SetConsoleTextAttribute ( hOut, LIGHT_GREEN );
            
putchar (RABBIT);
        
}
        
else if ( rcount < rabbitPosition )
        
{
            
SetConsoleTextAttribute (hOut, LIGHT_GREEN );
            
putchar (COMPLETE_ROAD);
        
}
        
else
        
{
            
SetConsoleTextAttribute ( hOut, LIGHT_YELLOW );
            
putchar (ROAD);
        
}
    
}
    
printf ("\n\n");
 
}


]]>
緇忓吀windows sdk 紼嬪簭璁捐緗戠珯 鈥斺旀湁濂界珯灝變細鏇存柊錛屽厤寰楀埌澶勫幓鎵?/title><link>http://www.shnenglu.com/k71983/archive/2008/05/22/50777.html</link><dc:creator>鑱傚厓鏈?/dc:creator><author>鑱傚厓鏈?/author><pubDate>Thu, 22 May 2008 08:27:00 GMT</pubDate><guid>http://www.shnenglu.com/k71983/archive/2008/05/22/50777.html</guid><wfw:comment>http://www.shnenglu.com/k71983/comments/50777.html</wfw:comment><comments>http://www.shnenglu.com/k71983/archive/2008/05/22/50777.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/k71983/comments/commentRss/50777.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/k71983/services/trackbacks/50777.html</trackback:ping><description><![CDATA[<a >http://www.winprog.org/tutorial/</a><br>涓漢鏈鍠滄鐨凷DK鍏ラ棬鏁欑▼ 浣跨敤C<br><br><a >http://www.relisoft.com/win32/index.htm</a><br>杈冨枩嬈㈢殑錛屼嬌鐢–++<br><br><a >http://adrianxw.dk/</a>   <br>涓浜涘叧浜巜indows涓嬬殑console鏂歸潰鐨凷DK鍑芥暟璋冪敤<br><br><a >http://www.functionx.com/win32/</a> <br><font color=#0000ff>This site's goal is to provide a few lessons on Win32 programming. Keep in mind that everything you can do with Win32 using a C++ compiler<br><br><a >http://www.mdstud.chalmers.se/~md7amag/code/wintut/</a><br>榪欎釜涓嶆槸澶ソ錛屼笉榪囩湅鐪嬩篃涓嶉敊<br><br>http://www.vckbase.com<br>寰堝婧愪唬鐮佸拰鏂囨湰璧勬枡錛屾枃妗o紝<br><br><a >http://www.<font color=#0000ff>c</font>sdn.net</a><br>榪欎釜涓嶇敤璇翠簡錛岄棶闂鐨勫ソ鍦版柟<br><br><a >http://ntt.cc/2008/05/12/over-480-free-and-fresh-icon-sets-help-you-to-create-your-beautiful-skins-and-themes-in-flex.html</a><br>鍚勭鍥捐〃璧勬簮绱㈠紩,欏轟究灝辯洿鎺ヤ粠鏀懼埌榪欓噷浜嗭紝鍏嶅緱榪樿鐐瑰嚮閾炬帴錛?br><br> <p>4 free icons of iPhone, designed in scribbled style. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=ipod align=left src="http://ntt.cc/wp-content/uploads/2008/05/ipod-thumb.png" width=200 height=137></a> </p> <p>  By: <a rel=nofollow target=_blank><font color=#006699>Dirceu Veiga</font></a> </p> <p>  Icons in package: 4 </p> <p>  </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Web 2 - Social Bookmark Icons</font></strong></a></p> <p>12 freeware “iPhone-like” icons of Web 2 Social Bookmarks for use in blogs, websites, desktops, softwares.</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=iPhone-like align=left src="http://ntt.cc/wp-content/uploads/2008/05/iphone-like-thumb.png" width=200 height=140></a> </p> <p>   By: <a rel=nofollow target=_blank><font color=#006699>Dirceu Veiga</font></a></p> <p>  Icons in package: 12 </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>iPod Shuffle Icons</font></strong></a></p> <p><a ><font color=#006699><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=ipodshuffle_preview align=left src="http://ntt.cc/wp-content/uploads/2008/05/ipodshuffle-preview-thumb.jpg" width=200 height=155></font></a> </p> <p>  By: <a rel=nofollow target=_blank><font color=#006699>Dirceu Veiga</font></a> </p> <p>  Icons in package: 2 </p> <p>  </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>3D RSS Feeds Icon</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=feeds align=left src="http://ntt.cc/wp-content/uploads/2008/05/feeds-thumb.jpg" width=200 height=145></a> </p> <p>  By:<a rel=nofollow target=_blank><font color=#006699>Dirceu Veiga</font></a> </p> <p>  Icons in package: 1</p> <p>  </p> <p>  </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Circle Feeds Icons</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=circle_feeds align=left src="http://ntt.cc/wp-content/uploads/2008/05/circle-feeds-thumb.jpg" width=200 height=156></a> </p> <p>  By:<a rel=nofollow target=_blank><font color=#006699>Dirceu Veiga</font></a> </p> <p>  Icons in package: 4</p> <p>  </p> <p>  </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Smiley DevKit</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=smiley_devkit align=left src="http://ntt.cc/wp-content/uploads/2008/05/smiley-devkit-thumb.png" width=200 height=191></a> By: <a rel=nofollow target=_blank><font color=#006699>bartelmedesign</font></a></p> <p> </p> <p>  </p> <p> </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Flag Button Devkit</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=flags align=left src="http://ntt.cc/wp-content/uploads/2008/05/flags-thumb.jpg" width=200 height=120></a>  By: <a rel=nofollow target=_blank><font color=#006699>bartelmedesign</font></a></p> <p>   </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Yellow Icon</font></strong></a> </p> <p>There are many types icons for free download, like PlayStation 3, SuperMan Returns, Star Wars…etc.. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=yellowicon align=left src="http://ntt.cc/wp-content/uploads/2008/05/yellowicon-thumb.png" width=200 height=123></a> </p> <p>By: <a rel=nofollow target=_blank><font color=#006699>yellowicon team</font></a></p> <p>  </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>OPENPHONE PACK</font></strong></a> </p> <p>This package includes icons inspirated on the new iPhone </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=openphone align=left src="http://ntt.cc/wp-content/uploads/2008/05/openphone-thumb.png" width=200 height=227></a> </p> <p>  Icons in package: 12 </p> <p>  Icons size: 256×256 </p> <p>  Icons formats: PNG, ICO </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Social Bookmark Iconset</font></strong></a> </p> <p>These icons designed by a chinese. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=socialbookmark align=left src="http://ntt.cc/wp-content/uploads/2008/05/socialbookmark-thumb.png" width=200 height=90></a> </p> <p>  By: <a rel=nofollow target=_blank><font color=#006699>yichi</font></a> </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Mac OS Boxes</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=1972_boxes align=left src="http://ntt.cc/wp-content/uploads/2008/05/1972-boxes-thumb.jpg" width=200 height=107></a> </p> <p>  By: <a rel=nofollow target=_blank><font color=#006699>Alejandro Lopez</font></a> </p> <p>  Icons in package: 6 </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>FastIcon.com</font></strong></a></p> <p>Icons by FastIcon.com: This artist has 41 icon sets containing 657 total icons for Mac OS X listed on InterfaceLIFT. The sets are shown in order of popularity.</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=FastIcon align=left src="http://ntt.cc/wp-content/uploads/2008/05/fasticon-thumb.png" width=200 height=151></a> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Iconshock’s Icon Sets</font></strong></a> </p> <p>There are many cartoon and film icons in the website include Transormers, Finding Nemo, Dragon Ball…  </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt="Iconshock’s Icon Sets" align=left src="http://ntt.cc/wp-content/uploads/2008/05/iconshocks-icon-sets-thumb.png" width=200 height=128></a> </p> <p>  </p> <p>  </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Adobe CS 3 Icon Pack</font></strong></a> </p> <p>9 PNG icons based on the design of Adobe CS3’s applications’ boxes </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=CS3_Icons_pack_by_Pedro_de_la_Luna align=left src="http://ntt.cc/wp-content/uploads/2008/05/cs3-icons-pack-by-pedro-de-la-luna-thumb.jpg" width=200 height=140></a> </p> <p>  By: Pedro de la Luna </p> <p>  Icons in package: 9 </p> <p> </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>CS 3 Icon Pack</font></strong></a> </p> <p>Including 28 icons, three for each CS3 application (Application - File - Folder) and one empty folder. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=CS3_Icons_pack_Reloaded_by_Pedro_de_la_Luna.png align=left src="http://ntt.cc/wp-content/uploads/2008/05/cs3-icons-pack-reloaded-by-pedro-de-la-lunapng-thumb.jpg" width=200 height=140></a> </p> <p>By: Pedro de la Luna </p> <p>  Icons in package: 9</p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>mAqua ChronoSync</font></strong></a> </p> <p>Free for personal use only, if for commercial use, need payment. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt="mAqua ChronoSync" align=left src="http://ntt.cc/wp-content/uploads/2008/05/maqua-chronosync-thumb.png" width=200 height=168></a> </p> <p>  </p> <p>  </p> <p>  </p> <p>  </p> <p>  </p> <p> </p> <p><strong>  </strong><a rel=nofollow target=_blank><strong><font color=#006699>Aqua Neue (Graphite)</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=01865_aquaneuegraphite align=left src="http://ntt.cc/wp-content/uploads/2008/05/01865-aquaneuegraphite-thumb.jpg" width=200 height=106></a> </p> <p>  By: Pedro de la Luna </p> <p>  Icons in package: 86 </p> <p> </p> <p> </p> <h5><a rel=nofollow target=_blank><font color=#006699>Feedicons 2</font></a></h5> <p><a ><font color=#006699><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=2 align=left src="http://ntt.cc/wp-content/uploads/2008/05/2-thumb.png" width=200 height=148></font></a> </p> <p>  By: Kuswanto </p> <p>  Download: </p> <p>  </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>104 Standard PC Keyboard Key Icons</font></strong></a> </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=pckeys1 align=left src="http://ntt.cc/wp-content/uploads/2008/05/pckeys1-thumb.jpg" width=200 height=175></a> </p> <p>  By: <a rel=nofollow target=_blank><font color=#006699>Alan Who</font></a> </p> <p>  Icons in package: 104 </p> <p>  Download: </p> <p>  </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Mac OS X Icons</font></strong></a> </p> <p>There are 248 icon sets in Mac OS X.</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt="Mac OS X Icons " align=left src="http://ntt.cc/wp-content/uploads/2008/05/mac-os-x-icons-thumb.png" width=200 height=169></a> </p> <p> </p> <p>  </p> <p>  </p> <p>  </p> <p>  </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Icon Bee</font></strong></a></p> <p>It is like a Bee collect many interesting free icon download website.  </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=iconbee align=left src="http://ntt.cc/wp-content/uploads/2008/05/iconbee-thumb.png" width=200 height=123></a> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Vistaicons.com</font></strong></a></p> <p>VistaIcons.com is a collection of free Vista Style icon sets of over 2500 high quality icons in png and ico format. From VistaIcons.com you can freely download 256×256 PNG icons for Windows Vista</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=Vistaicons align=left src="http://ntt.cc/wp-content/uploads/2008/05/vistaicons-thumb.png" width=200 height=148></a> </p> <p>  </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Free Microsoft Windows Icons</font></strong></a></p> <p>It has a big database of Windows icon artists and designers.</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=icons-win align=left src="http://ntt.cc/wp-content/uploads/2008/05/icons-win-thumb.png" width=200 height=152></a>  </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>famfamfam.com</font></strong></a> </p> <p>It is apersonal site and web playground of Birmingham (UK) based developer Mark James. There are many sets of icon for free download include silk web icons, flag icons…</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=famfamfam align=left src="http://ntt.cc/wp-content/uploads/2008/05/famfamfam-thumb.png" width=200 height=122></a> </p> <h5></h5> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>iconbuffet.com</font></strong></a></p> <p>IconBuffet is home to a tasty plethora of free icons. Collect them, download them, trade them with your friends. They’re kinda like baseball cards, only without the steroids. And you can use them on your website.</p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=IconBuffet align=left src="http://ntt.cc/wp-content/uploads/2008/05/iconbuffet-thumb.png" width=200 height=123></a> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>interfacelift.com</font></strong></a></p> <p>InterfaceLIFT is your source for graphical user interface enhancements for Mac OS X, Microsoft Windows, and Linux. They specialize in desktop wallpaper, icons, themes, and news with a focus on community. New content is posted virtually every day.</p> <p><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=InterfaceLIFT align=left src="http://ntt.cc/wp-content/uploads/2008/05/interfacelift.png" width=200 height=130> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>iconshock.com</font></strong></a> </p> <p>There are 497225 quality icons in 175 icon collections… and counting. </p> <p><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=iconshock align=left src="http://ntt.cc/wp-content/uploads/2008/05/iconshock.png" width=200 height=123> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>iconbase.com</font></strong></a> </p> <p>Here you´ll find the best icons from the best artists in the world. The icons here listed belong to the individual authors and companies. They are free for personal and non commercial use. If you are an icon artist and desire to share your work with the world, this is your place. Just click on the submit menu and follow the easy steps to add your icons. </p> <p><a ><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=iconbase align=left src="http://ntt.cc/wp-content/uploads/2008/05/iconbase-thumb.png" width=200 height=130></a>  </p> <p> </p> <p> </p> <p> </p> <p> </p> <p><a rel=nofollow target=_blank><strong><font color=#006699>Mintywhite.com</font></strong></a></p> <p>A list of 90 icon packs that you can download for free.<br>(include Vista High PX, Office Space Icon Set for Windows Vista, iVista Icon Pack, iVista Icon Pack 2, XP Icons,Royalty Free Icons for Toolbar and Web,Friendly Fire Icon Pack,Yoritsuki Icons,Antique Icons,Vista Glass Folder Icons,Arzo Icons Vol. 1,Gaming Icons Pack,Mario Galaxy Luma Icons,Christmas Icons,Wifun Icons by Rokey,Grzanka’s Icons,Fantastic Dream by Rokey,Eico 1 year by Rokey,128×128 Icons Set 5,Antares Iconset,Perfect Fanstasy,Monster Icons,128×128 Icons Set 4,iMac Icons,Camino Icons,Nes Icons Pack,iLife and iWork ‘08 Icons,Mouse Category Season 03 etc…)</p> <p><img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" border=0 alt=high-quality-free-icon-sets src="http://ntt.cc/wp-content/uploads/2008/05/high-quality-free-icon-sets.png" width=200 height=174></p> </font> <img src ="http://www.shnenglu.com/k71983/aggbug/50777.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/k71983/" target="_blank">鑱傚厓鏈?/a> 2008-05-22 16:27 <a href="http://www.shnenglu.com/k71983/archive/2008/05/22/50777.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鎸囬拡涓鈥斺斿熀鏈敤娉曞拰涓浜涢渶瑕佹竻妤氱殑姒傚康http://www.shnenglu.com/k71983/archive/2008/05/21/50700.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Wed, 21 May 2008 14:35:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/21/50700.htmlhttp://www.shnenglu.com/k71983/comments/50700.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/21/50700.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/50700.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/50700.html1.鎸囬拡鍙橀噺鐨勫0鏄庡拰鍒濆鍖?br>鎸囬拡灝辨槸鎶婂唴瀛樺湴鍧鍋氫負鍏跺肩殑鍙橀噺銆?br>(1)鎸囬拡鏄竴涓彉閲?br>(2)鏅氬彉閲忕洿鎺ュ紩鐢ㄤ簡涓涓?br>濡?

int a = 3;

閭d箞a鐨勫煎氨鏄?銆?br>(3)鎸囬拡鍙橀噺鍙瓨鏀懼唴瀛樺湴鍧
(4)鎸囬拡瀛樻斁鐨勫唴瀛樺湴鍧寰寰瀛樻斁鏈夊疄闄呯殑鍊鹼紝浣嗕篃鍙兘鏄彟澶栦竴涓寚閽?br>濡?

int a = 3;
int * aptr = &a;//鎶奱鐨勫湴鍧閫氳繃鍙栧湴鍧榪愮畻絎﹁祴緇欐寚閽堝彉閲?aptr
printf ("%p", aptr);//鎵撳嵃鍑烘寚閽堢殑鍊鹼紝鐢?6榪涘埗鐨勬柟寮?/span>
printf ("%p", &a);//鎵撳嵃鍑篴鐨勫湴鍧錛岀敤16榪涘埗鐨勬柟寮?/span>

(5)鎸囬拡鍙橀噺鍚嶉棿鎺ュ簲鐢ㄤ簡涓涓?鎴戜滑浣跨敤闂存帴寮曠敤榪愮畻絎︽潵鍙栧緱鍏蜂綋鐨勫?br>printf (”%d”, *aptr);

(6)鎸囬拡蹇呴』鍒濆鍖?鍙互鎶婃寚閽堝垵濮嬪寲涓篘ULL
NULL鍦?stdio.h>涓畾涔夛紝瀹冪殑鍊兼槸0
浣跨敤NULL浣跨▼搴忓叿鏈夊彲璇繪с?/p>

娉ㄦ剰錛?br>& 鍙栧湴鍧榪愮畻絎?鍙栧緱浠諱綍鍙橀噺鐨勫湴鍧
濡傦細

int a;
int *aptr;
int c[5];
//浣跨敤&榪愮畻絎﹀彇寰楀湴鍧錛屽茍鎵撳嵃鍑烘潵
printf ("%p\n", &a);//鍙栧緱鏁村瀷鍙橀噺a鐨勫唴瀛樺湴鍧
printf ("%p\n", &aptr);//鍙栧緱鎸囬拡鍙橀噺aptr鐨勫唴瀛樺湴鍧
printf ("%p\n", &c[0]);//鍙栧緱鏁扮粍絎竴涓厓绱犵殑鍐呭瓨鍦板潃

* 姣旇緝璁╁ぇ瀹惰糠鎯戠殑鏄畠鍦ㄨ繖閲屾湁涓ょ涓嶅悓鐨勭敤娉曪紝浣嗗疄闄呬笂瀹冧滑騫朵笉鏄悓鏍風殑
(1)鍜屽叿浣撶殑鏁版嵁綾誨瀷涓璧鋒瀯鎴愬搴旂殑鎸囬拡綾誨瀷
*鍦ㄥ0鏄庤鍙ヨ〃紺哄彉閲忔槸涓涓寚閽?/p>

int *
float *
char *
double *

(2)闂存帴寮曠敤榪愮畻絎?/p>

int a = 3;
int * aptr = &a;//鎶奱鐨勫湴鍧閫氳繃鍙栧湴鍧榪愮畻絎﹁祴緇欐寚閽堝彉閲?aptr
 
printf ("%d", *aptr);//閫氳繃a鐨勫湴鍧闂存帴寮曠敤鍙橀噺a鐨勫?/span>

鎬濊冿細
浠旂粏鍒嗘瀽涓嬮潰鐨勮鍙ョ殑緇撴灉銆?/p>

int a = 8;
int * aPtr;
aPtr = &a;
 
printf ("%p\n", & * aPtr);
printf ("%p\n", * & aPtr);

鎻愮ず錛屼竴灞傚眰鍒嗘瀽錛屽彲浠ョ湅鍋?&(*aPtr)
絳旀鍦ㄦ渶涓嬮潰銆?/p>

浜屻佹寚閽堢殑浼犲紩鐢ㄨ皟鐢?br>1.C璇█涓墍鏈夌殑鍑芥暟閮芥槸浼犲艱皟鐢?br>涓轟粈涔堬紝闅鵑亾鎸囬拡涓嶆槸浼犲紩鐢ㄨ皟鐢ㄥ悧錛?br>涓嶆槸錛孋璇█鍙槸鎶婃寚閽堢殑鍊兼嫹璐濅竴浠斤紝浼犲鍑芥暟鍐呴儴銆?br>2.閭d箞浼犻掓暟緇勫憿錛?/p>

void printArray (int *nPtr);

鍜?/p>

void printArray (int array[]);

鐨勬晥鏋滈兘鏄竴鏍風殑錛岄兘鏄紶涓涓湴鍧榪涘幓銆?br>鍙﹀錛岃娉ㄦ剰錛?br>鏁扮粍鍚嶆湰韜氨鏄湴鍧銆?br>3.鎸囬拡鐨勪紶寮曠敤璋冪敤鎴戜滑涔熷彲縐頒箣涓烘ā鎷熶紶寮曠敤璋冪敤錛屽洜涓烘垜浠紶鐨勬槸涓涓湴鍧錛?br>鍑芥暟璋冪敤鏃訛紝鍑芥暟鐨勫弬鏁頒細鎷瘋礉榪欎釜鍦板潃錛岀劧鍚庨氳繃澶嶅紩鐢ㄦ潵鎿嶄綔鍙橀噺銆?/p>

int cubeByReference (int * nPtr)//璁$畻绔嬫柟
{
    *
nptr = *nptr * *nptr * *nptr;
}

娉ㄦ剰榪欓噷錛?br>(1)*(澶嶅紩鐢ㄨ繍綆楃)姣?(涔樻硶榪愮畻絎?浼樺厛綰ц楂樸?br>鎵浠ュ彲浠ヤ笉閫傜敤鎷彿錛屼絾鏄帹鑽愪綘浣跨敤涓嬮潰鐨勮鍙ワ紝榪欐牱紼嬪簭鏇村姞娓呮櫚銆?br>(2)nPtr鏄崰鐢ㄥ爢鏍堢殑錛屽嚱鏁癱ubeByReference浼氱粰nPtr榪欎釜鎸囬拡鍙橀噺鍒嗛厤絀洪棿錛?br>鐒跺悗鎶婁紶鍏ョ殑鎸囬拡鍙橀噺鐨勫艱祴緇欏畠銆?/p>

int cubeByReference (int * nPtr)//璁$畻绔嬫柟
{
    
(*nptr) = (*nptr) * (*nptr) * (*nptr);
}

4.浼犲間負浠涔堜笉鏀瑰彉浼犲叆鍙橀噺鐨勫?br>鍥犱負瀹冩槸鍦ㄥ爢鏍堜腑鐢熸垚涓涓柊鐨勫彉閲忥紝鐒跺悗鎶婂瓨鏀劇殑鍊兼嫹璐濊繃鏉ワ紝鏈鍚庡嚱鏁扮粨鏉熺殑鏃跺欐妸璇ュ彉閲忎粠鍫嗘爤涓噴

鏀炬帀錛屾墍浠ュ茍涓嶄細鏀瑰彉浼犲叆鍙橀噺鐨勫箋?br>灝卞儚浣犵敤涓寮犳柊鐨勭焊鎶婁竴寮犵焊涓婄殑涓滆タ澶嶅埗涓閬嶏紝鐒跺悗鍦ㄦ柊鐨勭焊涓婂啓鍐欑敾鐢伙紝鐒跺悗涓㈡帀錛屽茍涓嶄細褰卞搷鍒板師鏉?/p>

鐨勭焊涓婄殑鍐呭銆?br>5.浼犳寚閽?涔熷氨鏄紶寮曠敤涓轟粈涔堜細鏀瑰彉)
鍥犱負鎸囬拡緇欏嚭浜嗗師鏉ュ彉閲忕殑鍦板潃錛屼嬌寰?(澶嶅紩鐢ㄦ寚閽?鍙互閫氳繃榪欎釜鍦板潃鎵懼埌榪欎釜鍙橀噺騫跺瀹冭繘琛屼慨鏀廣?/p>

涓夈佹寚閽堢殑const闄愬畾
(1)鎸囧悜闈炲父閲忔暟鎹殑闈炲父閲忔寚閽?/p>

int a;
int b;
int *aPtr;
aPtr = &a;//OK
aPtr = &b;//OK
*
aptr = 3;//OK

(2)鎸囧悜甯擱噺鏁版嵁鐨勯潪甯擱噺鎸囬拡(涓嶈兘淇敼鎸囧悜鍙橀噺涓殑鏁版嵁)

const int * aPtr;

娉ㄦ剰錛歝onst 淇グint

int a;
int b;
const int *aPtr;
aPtr = &a;//OK
aPtr = &b;//OK
*
aptr = 3;//ERROR 涓嶈兘淇敼鎸囧悜鐨勫彉閲忎腑鐨勬暟鎹?/span>

(3)鎸囧悜闈炲父閲忔暟鎹殑甯擱噺鎸囬拡(涓嶈兘涓滄寚瑗挎寚)

int * const aPtr;

娉ㄦ剰: const 淇グ鎸囬拡鍙橀噺 aptr;
鏁扮粍鍚嶆槸涓涓緢濂界殑渚嬪瓙銆?鍙傝瀛楃涓叉暟緇勪腑鐨勮鏄庛?

int a;
int b;
const int *aPtr = &a;
aPtr = &b;//ERROR  涓嶈兘鍐嶆寚鍚戝彟澶栦竴涓彉閲?/span>
*
aptr = 3;//OK

(4)鎸囧悜甯擱噺鏁版嵁鐨勫父閲忔寚閽?涓嶈兘淇敼鎸囧悜鍙橀噺涓殑鏁版嵁,涓嶈兘涓滄寚瑗挎寚)
const int * const aPtr;

int a;
int b;
const int * const aPtr = &a;
aPtr = &b;//ERROR  涓嶈兘鍐嶆寚鍚戝彟澶栦竴涓彉閲?/span>
*
aptr = 3;//ERROR  涓嶈兘淇敼鎸囧悜鐨勫彉閲忎腑鐨勬暟鎹?/span>

絳旀錛?br>1.瀹為檯涓?aPtr鐩稿綋浜巃, &*aPtr灝卞彇寰梐鐨勫湴鍧
2.&aPtr鍙栧緱aPtr鐨勭洿鑷籌紝鑰?&aPtr灝卞彇寰梐Ptr瀛樻斁鐨勫鹼紝涔熷氨鏄痑鐨勫湴鍧
3.&*浼氱浉浜掓姷娑堬紝瀹為檯涓?amp;*aPtr == aPtr == *&aPtr



]]>
瀛樺偍綾匯侀摼鎺ュ拰鍐呭瓨綆$悊(涓?鈥斺攙olatile鍜宺estricthttp://www.shnenglu.com/k71983/archive/2008/05/12/49619.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Mon, 12 May 2008 03:12:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/12/49619.htmlhttp://www.shnenglu.com/k71983/comments/49619.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/12/49619.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/49619.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/49619.html涓銆佺被鍨嬮檺瀹氳瘝volatile
闄愬畾璇峷olatile鍛婅瘔緙栬瘧鍣ㄨ鍙橀噺闄や簡鍙互琚▼搴忔敼鍙樹互澶栬繕鍙鍏朵粬浠g悊鏀瑰彉銆?br>瀹冮氬父琚敤浜庣‖浠跺湴鍧鍜屼笌鍏跺畠騫惰榪愯鐨勭▼搴忓叡浜殑鏁版嵁銆?br>濡傦細

volatile int locl;
volatile int *ploc;

浣犲彲鑳戒細濂囨負浠涔圓NSI瑙夊緱鏈夊繀瑕佹妸volatile浣滀負涓涓叧閿瓧銆?br>鍘熷洜鏄畠鍙互鏂逛究緙栬瘧鍣ㄤ紭鍖栥?br>渚嬪

val1 = x;
/* 涓浜涗笉浣跨敤x鐨勪唬鐮?*/
val2 = x;

涓涓仾鏄庣殑緙栬瘧鍣ㄥ彲鑳芥敞鎰忓埌浣犱嬌鐢ㄤ簡涓ゆx,鑰屾病鏈夋敼鍙樺畠鐨勫箋傞偅涔堬紝瀹冩湁鍙兘鎶妜涓存椂瀛樺偍鍦ㄤ竴涓瘎瀛樺櫒涓?br>鎺ョ潃錛屽綋val2闇瑕亁鏃訛紝鍙互閫氳繃浠庡瘎瀛樺櫒鑰岄潪鍒濆鐨勫唴瀛樹綅緗腑璇誨彇璇ュ間互鑺傜渷鏃墮棿銆?br>榪欎釜榪囩▼琚О涓虹紦瀛?caching)銆?br>閫氬父錛岀紦瀛樻槸涓涓ソ鐨勪紭鍖栨柟寮忥紝浣嗘槸濡傛灉鍦ㄤ袱涓鍙ラ棿鍏朵粬浠g悊鏀瑰彉浜唜鐨勮瘽灝變笉鏄繖鏍蜂簡銆?br>濡傛灉娌℃湁瑙勫畾volatile鍏抽敭瀛楋紝閭d箞緙栬瘧鍣ㄥ皢鏃犱粠寰楃煡榪欑鏀瑰彉鏄惁鍙兘鍙戠敓銆?br>鍦ˋNSI涓紝濡傛灉澹版槑涓病鏈塿olatile鍏抽敭瀛楋紝閭d箞緙栬瘧鍣ㄥ氨鍙互鍋囧畾涓涓煎湪浣跨敤榪囩▼涓病鏈夎淇敼錛屽畠灝卞彲浠ヨ瘯鐫浼?/p>

鍖栦唬鐮併?br>涓涓煎彲浠ュ悓鏃舵槸const 鍜?volatile銆?br>渚嬪錛岀‖浠舵椂閽熶竴鑸瀹氫負涓嶈兘鐢辯▼搴忔敼鍙橈紝榪欎竴鐐逛嬌瀹冩垚涓篶onst;
浣嗗畠琚▼搴忎互澶栫殑浠g悊鏀瑰彉錛岃繖浣垮畠鎴愪負volatile.
閭d箞鎴戜滑鍙互榪欎箞澹版槑錛?/p>

volatile const int loc;
const volatile int *ploc;

浜屻佺被鍨嬮檺瀹氳瘝restrict
鍏抽敭瀛梤estrict鐢ㄦ潵娑堥櫎鏁版嵁闂寸殑鐩稿叧鎬э紝緙栬瘧鍣ㄤ粠鑰屽彲浠ュ畨鎺掕鍙ョ殑騫惰鎵ц銆?br>瀹冨彧鍙互鐢ㄤ簬鎸囬拡錛屽茍琛ㄦ槑鎸囬拡鏄闂竴涓暟鎹璞$殑鍞竴涓斿垵濮嬬殑鏂瑰紡銆?br>鎴戜滑閫氳繃涓涓緥瀛愭潵鐪嬬湅錛?/p>

int ar[10];
int * par = ar;
int * restrict restar = (int *)malloc (10 * sizeof (int));

娉ㄦ剰錛屾寚閽坮estar鏄闂敱malloc ()鍒嗛厤鐨勫唴瀛樼殑鍞竴涓斿垵濮嬬殑鏂瑰紡銆?br>鍥犳錛屽畠鍙互鐢卞叧閿瓧restrict闄愬畾銆?br>鑰屾寚閽坧ar鏃笉鏄垵濮嬬殑錛屼篃涓嶆槸璁塊棶鏁扮粍ar涓暟鎹殑鍞竴鏂瑰紡錛屽洜姝や笉鍙互鎶婂畠闄愬畾涓簉estrict銆?br>鑰冭檻涓嬮潰鐨勮鍙ワ細

for (n = 0; n < 10; n++)
{
    
par[n] += 5;
    
restar[n] += 5;
    
ar[n] *= 2;
    
par[n] += 3;
    
restar[n] += 3;
}

鐭ラ亾浜唕estar鏄斁闂畠鎵鎸囧悜鏁版嵁鍧楃殑鍞竴鍒濆鍖栨柟寮忥紝緙栬瘧鍣ㄥ氨鍙互鐢ㄥ叿鏈夊悓鏍鋒晥鏋滅殑涓鏉¤鍙ユ潵浠f浛鍖呭惈restar鐨?/p>

涓や釜璇彞銆?/p>

resatr [n] += 8;

鐒惰岋紝緙栬瘧鍣ㄥ皢涓や釜鍖呭惈par鐨勮鍙ョ簿綆涓轟竴涓鍙ュ皢瀵艱嚧璁$畻閿欒銆?/p>

par[n] +=8;

鍘熷洜鏄痑r[n] *= 2;榪欐潯璇彞鍦╬ar[n] += 3涔嬪墠宸茬粡鏀瑰彉浜唒ar鎸囬拡鎵鎸囧悜鏁版嵁鐨勫箋?/p>

restrict鐨勪綔鐢細甯姪緙栬瘧鍣ㄧ‘瀹氫嬌鎸囬拡榪涜鏁板艱綆楁椂錛屾槸鍚﹀彲浠ヨ繘琛屼紭鍖栥?br>鍙互灝嗗叧閿瓧restrict浣滀負鎸囬拡鍨嬪嚱鏁板弬閲忕殑闄愬畾璇嶄嬌鐢ㄣ?br>榪欐剰鍛崇潃緙栬瘧鍣ㄥ彲浠ュ亣瀹氬湪鍑芥暟浣撳唴娌℃湁鍏跺畠鏍囪瘑絎︿慨鏀規寚閽堟寚鍚戠殑鏁版嵁錛屽洜鑰屽彲浠ヨ瘯鐫浼樺寲浠g爜錛屽弽涔嬪垯涓嶇劧銆?/p>

voie * memcpy (void * restrict s1, const void * restrict s2, size_t n);

鍏抽敭瀛梤estrict鏈変袱涓鑰呫?br>涓涓槸緙栬瘧鍣紝瀹冨憡璇夌紪璇戝櫒鍙互鑷敱鍦板幓鍋氫竴浜涙湁鍏充紭鍖栫殑鍋囧畾銆?br>涓涓槸鐢ㄤ簬錛屽畠鍛婅瘔鐢ㄦ埛浠呬嬌鐢ㄦ弧瓚硆estrict瑕佹眰鐨勫弬鏁般?/p>

]]>
瀛樺偍綾匯侀摼鎺ュ拰鍐呭瓨綆$悊(浜?鈥斺旈摼鎺ャ佸瓨鍌ㄦ椂鏈?/title><link>http://www.shnenglu.com/k71983/archive/2008/05/06/49041.html</link><dc:creator>鑱傚厓鏈?/dc:creator><author>鑱傚厓鏈?/author><pubDate>Tue, 06 May 2008 12:18:00 GMT</pubDate><guid>http://www.shnenglu.com/k71983/archive/2008/05/06/49041.html</guid><wfw:comment>http://www.shnenglu.com/k71983/comments/49041.html</wfw:comment><comments>http://www.shnenglu.com/k71983/archive/2008/05/06/49041.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/k71983/comments/commentRss/49041.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/k71983/services/trackbacks/49041.html</trackback:ping><description><![CDATA[<p>2.閾炬帴<br>涓涓狢鍙橀噺鍏鋒湁涓嬪垪閾炬帴涔嬩竴:<br>澶栭儴閾炬帴 (external linkage)<br>鍐呴儴閾炬帴 (internal linkage)<br>絀洪摼鎺?(no linkage)<br>鍏鋒湁浠g爜鍧椾綔鐢ㄥ煙鎴栬呭嚱鏁板師鍨嬩綔鐢ㄥ煙鐨勫彉閲忓叿鏈夌┖閾炬帴錛屾剰鍛崇潃瀹冧滑鏄敱鍏跺畾涔夋墍鍦ㄧ殑浠g爜鍧楁垨鍑芥暟鍘熷瀷鎵縐佹湁鐨勩?br>鍏鋒湁鏂囦歡浣滅敤鍩熺殑鍙橀噺鍙兘鏈夊唴閮ㄦ垨鑰呭閮ㄩ摼鎺ャ?br>涓涓叿鏈夊閮ㄩ摼鎺ョ殑鍙橀噺鍙互鍦ㄤ竴涓鏂囦歡紼嬪簭鐨勪換浣曞湴鏂逛嬌鐢ㄣ?br>涓涓叿鏈夊唴閮ㄩ摼鎺ョ殑鍙橀噺鍙互鍦ㄤ竴涓枃浠剁殑浠諱綍鍦版柟浣跨敤銆?br>閭f庢牱鐭ラ亾涓涓枃浠朵綔鐢ㄥ煙鍙橀噺鍏鋒湁鍐呴儴閾炬帴榪樻槸澶栭儴閾炬帴?<br>浣犲彲浠ョ湅鐪嬪湪澶栭儴瀹氫箟涓槸鍚︿嬌鐢ㄤ簡瀛樺偍綾昏鏄庣static:</p> <div id="5p5b5jr" class=hl-surround> <div id="ztt135l" class=hl-main><span id="n55zzz5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">giants</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">5</span><span style="COLOR: gray">;</span><span style="COLOR: #ffa500">//鏂囦歡浣滅敤鍩燂紝澶栭儴閾炬帴</span><span style="COLOR: gray"><br></span><span id="fxz3jz3" class=hl-types>static</span><span style="COLOR: gray"> </span><span id="nf5n55j" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">dodgers</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">3</span><span style="COLOR: gray">;</span><span style="COLOR: #ffa500">//鏂囦歡浣滅敤鍩燂紝鍐呴儴閾炬帴</span><span style="COLOR: gray"><br></span><span id="3d5vf55" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">()</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    ……<br></span><span style="COLOR: olive">}</span></div> </div> <p>鍜岃鏂囦歡灞炰簬鍚屼竴紼嬪簭鐨勫叾浠栨枃浠跺彲浠ヤ嬌鐢ㄥ彉閲廹iants銆?br>鍙橀噺dodgers鏄鏂囦歡縐佹湁鐨勶紝浣嗘槸鍙互琚鏂囦歡涓殑浠諱竴鍑芥暟浣跨敤銆?/p> <p>2.瀛樺偍鏃舵湡<br>涓涓狢鍙橀噺鏈変袱縐嶅瓨鍌ㄦ椂鏈熶箣涓錛?br>闈欐佸瓨鍌ㄦ椂鏈?static storage duration)鍜岃嚜鍔ㄥ瓨鍌ㄦ椂鏈?automatic storage duration)銆?br>濡傛灉涓涓彉閲忓叿鏈夐潤鎬佸瓨鍌ㄦ椂鏈燂紝瀹冨湪紼嬪簭鎵ц鏈熼棿灝嗕竴鐩村瓨鍦ㄣ?br>鍏鋒湁鏂囦歡浣滅敤鍩熺殑鍙橀噺鍏鋒湁闈欐佸瓨鍌ㄦ椂鏈熴?br>娉ㄦ剰瀵逛簬鍏鋒湁鏂囦歡浣滅敤鍩熺殑鍙橀噺錛屽叧閿瓧static琛ㄧず閾炬帴綾誨瀷錛屽茍闈炲瓨鍌ㄦ椂鏈熴?br>鍥犱負鎵鏈夌殑鏂囦歡浣滅敤鍩熷彉閲忥紝鏃犺瀹冨叿鏈夊唴閮ㄩ摼鎺ワ紝榪樻槸鍏鋒湁澶栭儴閾炬帴錛岄兘鍏鋒湁闈欐佸瓨鍌ㄦ椂鏈熴?/p> <p>鍏鋒湁浠g爜鍧椾綔鐢ㄥ煙鐨勫彉閲忎竴鑸儏鍐典笅鍏鋒湁鑷姩瀛樺偍鏃舵湡銆?br>褰撶▼搴忚繘鍏ュ畾涔夎繖浜涘彉閲忕殑浠g爜鍧楁椂錛屽皢涓鴻繖浜涘彉閲忓垎閰嶅唴瀛樸?br>褰撴帹鍑鴻繖涓唬鐮佸潡鏃訛紝鍐呭瓨灝嗚閲婃斁銆?br>榪欐牱錛屽湪涓涓嚱鏁拌皟鐢ㄧ粨鏉熷悗錛屽畠鐨勫彉閲忔墍鍗犵敤鐨勫唴瀛樼┖闂村彲浠ョ敤鏉ュ瓨鍌ㄤ笅涓涓璋冪敤鍑芥暟鐨勫彉閲忋?/p> <p>鍒扮幇鍦ㄦ垜浠墍浣跨敤鐨勫眬閮ㄥ彉閲忛兘灞炰簬鑷姩綾誨瀷銆?/p> <div id="r3nfh55" class=hl-surround> <div id="d555vdf" class=hl-main><span id="xzbpjhn" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">bore</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="t3hj5hf" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">number</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="5x3xtz5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">index</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: green">for</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: blue">index</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">0</span><span style="COLOR: gray">; </span><span style="COLOR: blue">index</span><span style="COLOR: gray"> < </span><span style="COLOR: blue">number</span><span style="COLOR: gray">; </span><span style="COLOR: blue">index</span><span style="COLOR: gray">++</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br>    </span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>        </span><span style="COLOR: blue">puts</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">They don't make them the way they used to.</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>        </span><span style="COLOR: green">return</span><span style="COLOR: gray"> </span><span style="COLOR: maroon">0</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">}</span></div> </div> <p>鎬昏錛歝浣跨敤浣滅敤鍩熴侀摼鎺ュ拰瀛樺偍鏃舵湡鏉ュ畾涔?涓瓨鍌ㄧ被銆?br>鑷姩錛屽瘎瀛樺櫒銆佸叿鏈変唬鐮佸潡浣滅敤鍩熺殑闈欐併佸叿鏈夊閮ㄩ摼鎺ョ殑闈欐併佸叿鏈夊唴閮ㄩ摼鎺ョ殑闈欐?br>1.鑷姩鍙橀噺<br>鑷姩鍙橀噺鍏鋒湁鑷姩瀛樺偍鏃舵湡銆佷唬鐮佸潡浣滅敤鍩熷拰絀洪摼鎺ャ?br>榛樿鎯呭喌涓嬶紝鍦ㄤ唬鐮佸潡鎴栧嚱鏁扮殑澶撮儴瀹氫箟鐨勪換鎰忓彉閲忛兘灞炰簬鑷姩瀛樺偍綾匯?br>浣犲彲浠ユ樉紺虹殑浣跨敤鍏抽敭瀛梐uto鏉ヨ〃鏄庝竴涓彉閲忎負鑷姩鍙橀噺錛屼絾鎴戜滑涓鑸笉鍐欍?/p> <div id="3v35vbr" class=hl-surround> <div id="3t5rbt5" class=hl-main><span id="x3f35lj" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="v3vbd3x" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="3plz5vv" class=hl-types>auto</span><span style="COLOR: gray"> </span><span id="vrt3fl5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">plox</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br> <br></span><span id="rb35xvf" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">loop</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="3zlrt55" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">n</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="vx55rpn" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">m</span><span style="COLOR: gray">;  </span><span style="COLOR: #ffa500">// m鐨勪綔鐢ㄥ煙</span><span style="COLOR: gray"><br>    </span><span style="COLOR: blue">scanf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">%d</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, &</span><span style="COLOR: blue">m</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>        </span><span id="fn5zbbx" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">i</span><span style="COLOR: gray">; </span><span style="COLOR: #ffa500">// m鍜宨鐨勪綔鐢ㄥ煙</span><span style="COLOR: gray"><br>        </span><span style="COLOR: green">for</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: blue">i</span><span style="COLOR: gray">=</span><span style="COLOR: blue">m</span><span style="COLOR: gray">; </span><span style="COLOR: blue">i</span><span style="COLOR: gray"> < </span><span style="COLOR: blue">n</span><span style="COLOR: gray">; </span><span style="COLOR: blue">i</span><span style="COLOR: gray">++</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br>        </span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>            </span><span style="COLOR: blue">puts</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">i is local to a sub-block</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>        </span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br>    </span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br>    <br>    </span><span style="COLOR: green">return</span><span style="COLOR: gray"> </span><span style="COLOR: blue">m</span><span style="COLOR: gray">;  </span><span style="COLOR: #ffa500">// m鐨勪綔鐢ㄥ煙, i宸茬粡娑堝け</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">}</span></div> </div> <p>濡傛灉鍦ㄥ唴灞備唬鐮佸潡瀹氫箟浜嗕竴涓叿鏈夊拰澶栧眰浠g爜鍧椾究鏉ラ偅涓悓涓鍚嶅瓧鐨勫彉閲忥紝灝嗕細鎬庢牱?<br>(鏈濂戒笉瑕佸湪浣犵殑浠g爜涓繖鏍峰仛)<br>榪欐椂鍐呭眰浠g爜鍧楀皢浣跨敤鍦ㄥ唴灞備唬鐮佸潡涓繖涓柊瀹氫箟鐨勫彉閲忋?br>鎴戜滑縐頒箣涓哄唴灞傚畾涔夎鐩?hide)浜嗗閮ㄥ畾涔夛紝鍙湁褰撹繍琛岀寮鍐呭眰浠g爜鍧楁槸錛屽閮ㄥ彉閲忔墠浼氶噸鏂版仮澶嶄嬌鐢ㄣ?/p> <div id="b3jvnd3" class=hl-surround> <div id="xhj53fd" class=hl-main><span id="lx53zpv" class=hl-prepro>#include </span><span style="COLOR: #8b0000"><</span><span style="COLOR: red">stdio.h</span><span style="COLOR: #8b0000">></span><span id="n3555n5" class=hl-prepro></span><span style="COLOR: gray"><br></span><span id="53bdfvb" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="tdxtx5t" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="5pzxrnd" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">x</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">30</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">x in outer block: %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">x</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>        </span><span id="lnxrl5p" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">x</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">77</span><span style="COLOR: gray">;<br>        </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">x in inner block: %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">x</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">}</span></div> </div> <p>娉ㄦ剰錛?br>c99涓瀹氾紝璇彞鑻ヤ負寰幆鎴栬卛f璇彞鐨勪竴閮ㄥ垎錛屽嵆浣挎病鏈変嬌鐢▄},涔熻涓烘槸涓涓唬鐮佸潡銆?/p> <div id="zztf5v5" class=hl-surround> <div id="ppj5f55" class=hl-main><span id="xrvnhn3" class=hl-prepro>#include </span><span style="COLOR: #8b0000"><</span><span style="COLOR: red">stdio.h</span><span style="COLOR: #8b0000">></span><span id="3bd5pdt" class=hl-prepro></span><span style="COLOR: gray"><br></span><span id="5x5355p" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="bbl3zfd" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="3jtbpv5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">n</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">10</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">Initially, n = %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">n</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    <br>    </span><span style="COLOR: green">for</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="bldnhxl" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">n</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">; </span><span style="COLOR: blue">n</span><span style="COLOR: gray"> < </span><span style="COLOR: maroon">3</span><span style="COLOR: gray">; </span><span style="COLOR: blue">n</span><span style="COLOR: gray">++</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br>        </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">loop : n = %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">n</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    <br>    </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">Initially, n = %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">n</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>    <br>    </span><span style="COLOR: green">return</span><span style="COLOR: gray"> </span><span style="COLOR: maroon">0</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span></div> </div> <p>娉ㄦ剰錛?br>闄ら潪鎮ㄦ樉寮忓湴鍒濆鍖栬嚜鍔ㄥ彉閲忥紝鍚﹀垯瀹冧笉浼氳鑷姩鍒濆鍖栥?/p> <div id="jrl5bpf" class=hl-surround> <div id="5fr5l55" class=hl-main><span id="jt333f5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="z3lnhvl" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="dnpl5dj" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">repid</span><span style="COLOR: gray">;<br>    </span><span id="rblf35h" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">tents</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">5</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span></div> </div> <p>repid鐨勫垵鍊煎垯鏄厛鍓嶅崰鐢ㄥ垎閰嶇粰瀹冪殑絀洪棿鐨勪換鎰忓箋備笉瑕佹寚鏈涜繖涓兼槸0銆?/p> <p>2.瀵勫瓨鍣ㄥ彉閲?br>閫氬父錛屽彉閲忓瓨鍌ㄥ湪璁$畻鏈哄唴瀛樹腑銆傚鏋滃垢榪愶紝瀵勫瓨鍣ㄥ彉閲忓彲浠ヨ瀛樺偍鍦–PU鐨勫瘎瀛樺櫒涓紝榪欐牱閫熷害浼氭洿蹇?br>鍦ㄥ叾瀹冭澶氭柟闈紝瀹冨拰鑷姩鍙橀噺鏄竴鏍風殑銆?br>閫氳繃浣跨敤瀛樺偍綾誨瀷璇存槑絎egister鍙互澹版槑瀵勫瓨鍣ㄥ彉閲忋?/p> <div id="btv5zr3" class=hl-surround> <div id="3j5z535" class=hl-main><span id="3j3vxn5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="b3j3v5f" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="335zbbp" class=hl-types>register</span><span style="COLOR: gray"> </span><span id="bln5lj3" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">quick</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span></div> </div> <p>鎴戜滑璇村鏋滃垢榪愭槸鍥犱負澹版槑涓涓瘎瀛樺櫒綾誨彉閲忎粎浠呮槸涓涓姹傦紝鑰屼笉鏄竴鏉$洿鎺ュ懡浠ゃ?br>鍥犱負CPU瀵勫瓨鍣ㄥ線寰寰堝皯錛岀紪璇戝櫒蹇呴』鍦ㄥ彲鐢ㄥ瘎瀛樺櫒鐨勪釜鏁板拰鍙敤楂橀熷唴瀛樼殑鏁伴噺涔嬮棿鍋氭潈琛°?br>榪欑鎯呭喌涓嬶紝鍙橀噺鎴愪負涓涓櫘閫氱殑鑷姩鍙橀噺銆?br>浣嗘槸錛屼綘涓嶈兘瀵瑰畠浣跨敤鍦板潃榪愮畻絎︺?br>鍙互鎶婁竴涓艦寮忓弬閲忚姹備負瀵勫瓨鍣ㄥ彉閲忋?/p> <div id="r35j5p5" class=hl-surround> <div id="jtvtljr" class=hl-main><span id="fhbv5x3" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">macho</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="3zbd35v" class=hl-types>register</span><span style="COLOR: gray"> </span><span id="tl5rl55" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">n</span><span style="COLOR: olive">)</span></div> </div> <p>3.鍏鋒湁浠g爜鍧椾綔鐢ㄥ煙鐨勯潤鎬佸彉閲?br>闈欐佸彉閲忓儚鏄竴涓笉鍙彉鐨勫彉閲忋?br>浣嗗疄闄呬笂錛岄潤鎬佹寚鍙橀噺鐨勭殑浣嶇疆鍥哄畾涓嶅姩銆?br>鍏鋒湁鏂囦歡浣滅敤鍩熺殑鍙橀噺鑷姩鐨勫叿鏈夐潤鎬佸瓨鍌ㄦ椂鏈熴?br>涔熷彲浠ュ垱寤哄叿鏈変唬鐮佸潡浣滅敤鍩燂紝鍏煎叿鏈夐潤鎬佸瓨鍌ㄧ殑灞閮ㄥ彉閲忋?br>榪欎簺鍙橀噺鍜岃嚜鍔ㄥ彉閲忓叿鏈夌浉鍚岀殑浣滅敤鍩燂紝褰撳寘鍚繖浜涘彉閲忕殑鍑芥暟瀹屾垚宸ヤ綔鏃訛紝瀹冧滑騫朵笉娑堝け銆?br>浠庝竴嬈″嚱鏁拌皟鐢ㄥ埌涓嬩竴嬈¤皟鐢紝璁$畻鏈洪兘璁板綍鐫浠栦滑鐨勫箋?br>鎴戜滑鍙互浣跨敤瀛樺偍綾昏鏄庣static鍦ㄤ唬鐮佸潡鍐呭0鏄庤繖浜涘彉閲忋?/p> <div id="rbdf3xx" class=hl-surround> <div id="5jbnjh5" class=hl-main><span id="z5pj55h" class=hl-prepro>#include </span><span style="COLOR: #8b0000"><</span><span style="COLOR: red">stdio.h</span><span style="COLOR: #8b0000">></span><span id="nxzl3hn" class=hl-prepro></span><span style="COLOR: gray"><br></span><span id="5xzl5n3" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">trystat</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="lnx53zx" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br></span><span id="nppjpdb" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="5xh35l5" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="n3dfvbr" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">count</span><span style="COLOR: gray">;<br> <br>    </span><span style="COLOR: green">for</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: blue">count</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">; </span><span style="COLOR: blue">count</span><span style="COLOR: gray"> <= </span><span style="COLOR: maroon">3</span><span style="COLOR: gray">; </span><span style="COLOR: blue">count</span><span style="COLOR: gray">++</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br>    </span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>        </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">Here comes iteration %d:</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">count</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br>        </span><span style="COLOR: blue">trystat</span><span style="COLOR: gray"> </span><span style="COLOR: olive">()</span><span style="COLOR: gray">;<br>    </span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br>    <br>    </span><span style="COLOR: green">return</span><span style="COLOR: gray"> </span><span style="COLOR: maroon">0</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br> <br></span><span id="5rl3tl3" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">trystat</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="pp3l3bz" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="5tnpttz" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">fade</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">;<br>    </span><span id="bjd53jh" class=hl-types>static</span><span style="COLOR: gray"> </span><span id="33j5v5b" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">stay</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">;<br>    <br>    </span><span style="COLOR: blue">printf</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">"</span><span style="COLOR: red">fade = %d and stay = %d</span><span style="COLOR: navy">\</span><span style="COLOR: red">n</span><span style="COLOR: #8b0000">"</span><span style="COLOR: gray">, </span><span style="COLOR: blue">fade</span><span style="COLOR: gray">++, </span><span style="COLOR: blue">stay</span><span style="COLOR: gray">++</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br></span><span style="COLOR: olive">}</span></div> </div> <p>娉ㄦ剰錛?br>瀵瑰嚱鏁板弬鏁頒笉鑳戒嬌鐢╯tatic銆?br>4.鍏鋒湁澶栭儴閾炬帴鐨勯潤鎬佸彉閲?br>鍏鋒湁澶栭儴閾炬帴鐨勯潤鎬佸彉閲忓叿鏈夋枃浠朵綔鐢ㄥ煙銆佸閮ㄩ摼鎺ュ拰闈欐佸瓨鍌ㄦ椂鏈熴?br>榪欎竴綾誨瀷鐨勫彉閲忔垚涓哄閮ㄥ彉閲?external variable銆?br>鎶婂彉閲忕殑瀹氫箟澹版槑鏀懼湪鎵鏈夊嚱鏁頒箣澶栵紝鍗沖垱寤轟簡涓涓閮ㄥ彉閲忋?br>涓轟簡浣跨▼搴忔洿鍔犳竻鏅幫紝鍙互鍦ㄤ嬌鐢ㄥ閮ㄥ彉閲忕殑鍑芥暟涓氳繃浣跨敤extern鍏抽敭瀛楁潵鍐嶆澹版槑瀹冦?br>濡傛灉鍙橀噺鏄湪鍒殑鏂囦歡涓畾涔夌殑錛屼嬌鐢╡xtern鏉ュ0鏄庤鍙橀噺灝辨槸蹇呴』鐨勩?/p> <div id="z3jtxvj" class=hl-surround> <div id="x5h3p35" class=hl-main><span id="l3tnzz3" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">Errupt</span><span style="COLOR: gray">;  </span><span style="COLOR: #ffa500">//澶栭儴瀹氫箟鐨勫彉閲?/span><span style="COLOR: gray"><br></span><span id="j5b3lbp" class=hl-types>double</span><span style="COLOR: gray"> </span><span style="COLOR: blue">Up</span><span style="COLOR: olive">[</span><span style="COLOR: maroon">100</span><span style="COLOR: olive">]</span><span style="COLOR: gray">; </span><span style="COLOR: #ffa500">//澶栭儴澹版槑鐨勬暟緇?/span><span style="COLOR: gray"><br></span><span id="t1p355z" class=hl-types>extern</span><span style="COLOR: gray"> </span><span id="53555l5" class=hl-types>char</span><span style="COLOR: gray"> </span><span style="COLOR: blue">Coal</span><span style="COLOR: gray">; </span><span style="COLOR: #ffa500">//蹇呴』鐨勫0鏄庯紝鍥犱負Coal鍦ㄥ叾瀹冩枃浠朵腑瀹氫箟</span><span style="COLOR: gray"><br> <br></span><span id="d5h3j5x" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">next</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="vz55555" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray">;<br></span><span id="hd535r5" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">main</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="nztl3vl" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br>    </span><span id="t35ldt5" class=hl-types>extern</span><span style="COLOR: gray"> </span><span id="bx55z53" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">Errupt</span><span style="COLOR: gray">;</span><span style="COLOR: #ffa500">//鍙夌殑澹版槑</span><span style="COLOR: gray"><br>    </span><span id="frlvnt5" class=hl-types>extern</span><span style="COLOR: gray"> </span><span id="fp5vflj" class=hl-types>double</span><span style="COLOR: gray"> </span><span style="COLOR: blue">Up</span><span style="COLOR: olive">[]</span><span style="COLOR: gray">;</span><span style="COLOR: #ffa500">//鍙夌殑澹版槑</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">}</span><span style="COLOR: gray"><br></span><span id="t3vf3v5" class=hl-types>void</span><span style="COLOR: gray"> </span><span style="COLOR: blue">next</span><span style="COLOR: gray"> </span><span style="COLOR: olive">(</span><span id="n53fpp5" class=hl-types>void</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">{</span><span style="COLOR: gray"><br></span><span style="COLOR: olive">}</span></div> </div> <p>娉ㄦ剰錛?br>涓嶅悓浜庤嚜鍔ㄥ彉閲忥紝濡傛灉鎮ㄤ笉瀵瑰閮ㄥ彉閲忚繘琛屽垵濮嬪寲錛屼粬浠皢鑷姩琚祴鍒濆?銆?br>榪欎竴鍘熷垯涔熼傜敤浜庡閮ㄥ畾涔夌殑鏁扮粍銆?/p> <p>5.鍏鋒湁鍐呴儴闈欐侀摼鎺ョ殑闈欐佸彉閲?br>閫氳繃浣跨敤瀛樺偍綾昏鏄庣(娉ㄦ剰涓嶆槸闈欐佸彉閲忓0鏄庣)static鍦ㄦ墍鏈夊嚱鏁扮殑澶栭儴榪涜瀹氫箟錛屽墠闈㈠凡緇忚榪囪鍙橀噺涓烘暣涓枃浠剁鏈?/p> <p>錛岃繖閲屼笉鍐嶈璁恒?/p> <div id="zrln3v3" class=hl-surround> <div id="nf3tvt3" class=hl-main><span id="5v5fzhx" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">traveler</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">; </span><span style="COLOR: #ffa500">//澶栭儴閾炬帴</span><span style="COLOR: gray"><br></span><span id="3jf555x" class=hl-types>static</span><span style="COLOR: gray"> </span><span id="5dpjj35" class=hl-types>int</span><span style="COLOR: gray"> </span><span style="COLOR: blue">stayhome</span><span style="COLOR: gray"> = </span><span style="COLOR: maroon">1</span><span style="COLOR: gray">; </span><span style="COLOR: #ffa500">//鍐呴儴閾炬帴</span></div> </div> <img src ="http://www.shnenglu.com/k71983/aggbug/49041.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/k71983/" target="_blank">鑱傚厓鏈?/a> 2008-05-06 20:18 <a href="http://www.shnenglu.com/k71983/archive/2008/05/06/49041.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>瀛樺偍綾匯侀摼鎺ュ拰鍐呭瓨綆$悊(涓)鈥斺斾綔鐢ㄥ煙http://www.shnenglu.com/k71983/archive/2008/05/06/49028.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Tue, 06 May 2008 10:21:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/06/49028.htmlhttp://www.shnenglu.com/k71983/comments/49028.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/06/49028.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/49028.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/49028.html瀛樺偍綾匯侀摼鎺ュ拰鍐呭瓨綆$悊
1.浣滅敤鍩?br>浣滅敤鍩熸弿榪頒簡紼嬪簭涓彲浠ヨ闂竴涓爣璇嗙鐨勪竴涓垨澶氫釜鍖哄煙銆?br>涓涓狢鍙橀噺鐨勪綔鐢ㄥ煙鍙互鏄唬鐮佸潡浣滅敤鍩熴佸嚱鏁板師鍨嬩綔鐢ㄥ煙鎴栬呮枃浠朵綔鐢ㄥ煙銆?br>浠g爜鍧椾綔鐢ㄥ煙
涓涓唬鐮佸潡鏄寘鍚湪寮濮嬭姳鎷彿鍜屽搴旂殑緇撴潫鑺辨嫭鍙蜂箣鍐呯殑涓孌典唬鐮併?br>渚嬪錛屾暣涓嚱鏁頒綋鏄竴涓唬鐮佸潡銆?br>涓涓嚱鏁板唴鐨勪換涓澶嶅悎璇彞涔熸槸浠g爜鍧椼?br>鍦ㄤ唬鐮佸揩涓畾涔夌殑鍙橀噺鍏鋒湁浠g爜鍧椾綔鐢ㄥ煙(block scope),浠庤鍙橀噺琚畾涔夌殑鍦版柟鍒板寘鍚瀹氫箟鐨勪唬鐮佸潡鐨勬湯灝捐鍙橀噺鍧囧彲瑙?/p>

銆?br>鍙﹀錛屽嚱鏁扮殑褰㈠紡鍙傛暟灝界鍦ㄥ嚱鏁扮殑寮濮嬭姳鎷彿鍓嶈繘琛屽畾涔夛紝涔熷悓鏍峰叿鏈変唬鐮佸潡浣滅敤鍩?騫朵笖灞炰簬鍖呭惈鍑芥暟浣撶殑浠g爜鍧椼?/p>

double blocky (double cleo)
{
    
double patrick = 0.0;
    
    
return patrick;
}

鍦ㄤ笂闈㈣繖涓緥瀛愪腑錛宑leo鍜宲atrick閮芥湁鐭ラ亾緇撴潫鑺辨嫭鍙風殑浠g爜浣滅敤鍩熴?/p>

鍦ㄤ竴涓唴閮ㄤ唬鐮佸潡涓0鏄庣殑鍙橀噺錛屽叾浣滅敤鍩熷彧灞闄愪簬璇ヤ唬鐮佸潡錛?/p>

double blocky (double cleo)
{
    
double patrick = 0.0;
    
int i;
    
for (i=0; i < 10; i++)
    
{
        
double q = cleo * i// q浣滅敤鍩熺殑寮濮?/span>
        ……
        
patrick *= q;
    
}//q浣滅敤鍩熺殑緇撴潫
    
return patrick;
}

鍦ㄨ繖涓緥瀛愪腑錛宷鐨勪綔鐢ㄥ煙琚檺鍒跺湪鍐呴儴浠g爜鍧楀唴錛屽彧鏈夎浠g爜鍐呯殑浠g爜鍙互璁塊棶q銆?br>C99鍏佽鍦ㄤ竴涓唬鐮佸潡涓殑浠諱綍浣嶇疆澹版槑鍙橀噺錛屼嬌鐢ㄤ箣鍓嶈娉ㄦ剰緙栬瘧鍣ㄨ兘涓嶈兘鏀寔銆?br>濡傦紝浣犲彲浠ヨ繖鏍峰0鏄?/p>

for (int i=0; i < 10; i++ )
{
    
printf ("A C99 feature: i=%d", i);
}

2.鍑芥暟鍘熷瀷浣滅敤鍩?br>浠庡彉閲忓畾涔夊涓鐩村埌鍘熷瀷澹版槑鐨勬湯灝撅紝榪欐剰鍛崇潃緙栬瘧鍣ㄥ湪澶勭悊涓涓嚱鏁板師鍨嬬殑鍙傛暟鏃訛紝瀹冩墍鍏沖績鐨勫彧鏄鍙傛暟鐨勭被鍨嬶紱鎮ㄤ嬌

鐢ㄧ殑鍚嶅瓧鏄棤鍏崇揣瑕佺殑銆?/p>

int mighty (int mouse, double large);

3.鏂囦歡浣滅敤鍩?br>涓涓湪鎵鏈夊嚱鏁頒箣澶栧畾涔夌殑鍙橀噺鍏鋒湁鏂囦歡浣滅敤鍩?(file scope)銆?br>鍏鋒湁鏂囦歡浣滅敤鍩熺殑渚跨嫾浠庡畠瀹氫箟澶勫埌鍖呭惈璇ュ畾涔夌殑鏂囦歡緇撳熬澶勯兘鏄彲瑙佺殑銆?/p>

#include <stdio.h>
int units = 0;//鍏鋒湁鏂囦歡浣滅敤鍩熺殑鍙橀噺
void critic (void);
int main (void)
{
    ……
}
 
void critic (void)
{
    ……
}

榪欓噷錛屽彉閲弖nits鍏鋒湁鏂囦歡浣滅敤鍩燂紝鍦╩ain ()鍜宑ritic ()涓兘鍙互浣跨敤瀹冦傚洜涓哄畠浠彲浠ュ湪涓嶆涓涓嚱鏁頒腑浣跨敤錛屾枃浠朵綔鐢ㄥ煙鍙橀噺涔熻縐頒負鍏ㄥ眬鍙橀噺(global varibale)銆?/p>

4.goto
鍑芥暟浣滅敤鍩熷彧閫傜敤浜巊oto璇彞浣跨敤鐨勬爣絳俱傚嚱鏁頒綔鐢ㄥ煙鎰忓懗鐫涓涓壒瀹氬嚱鏁頒腑鐨刧oto鏍囩瀵硅鍑芥暟涓換浣曞湴鏂圭殑浠g爜閮芥槸鍙鐨勶紝鏃犺璇ユ爣絳懼嚭鐜板湪鍝竴涓唬鐮佸潡涓?/p>

]]>
瀛楃涓插嚱鏁?涓?http://www.shnenglu.com/k71983/archive/2008/05/06/49009.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Tue, 06 May 2008 07:28:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/06/49009.htmlhttp://www.shnenglu.com/k71983/comments/49009.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/06/49009.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/49009.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/49009.html1.strncmp ()鍑芥暟
strncmp ()鍑芥暟鍙互姣旇緝鍒板瓧絎︿覆鐨勪笉鍚屽錛屼篃鍙互姣旇緝瀹岀敱絎笁涓弬鏁版寚瀹氱殑瀛楃涓層?br>渚嬪錛屽鏋滄兂鎼滅儲浠?#8221;astro”寮澶寸殑瀛楃涓詫紝鎮ㄥ彲浠ラ檺瀹氭悳绱㈠墠5涓瓧絎︺?/p>
//浣跨敤strncmp ()鍑芥暟
#include <stdio.h>
#inlcude <string.h>
 
#define LISTSIZE 5
 
int main (void)
{
    
char * list[LISTSIZE] = {
                
"astronomy", "astounding",
                
"astrophysics", "ostracize",
                
"asterism"   
                
};
    
int count = 0;
    
int i;
    
    
for (i=0; i < LISTSIZE; i++)
    
{
        
if (strncmp (list[i], "astro", 5) == 0)
        
{
            
printf ("Found: %s\n", list[i]);
            
count++;
        
}
    
}
    
    
printf ("The list contained %d words beginning with astro.\n", count);
    
    
return 0;
}

2.strcpy () 鍜宻trncpy ()鍑芥暟
濡傛灉pts1鍜宲ts2閮芥槸鎸囧悜瀛楃涓茬殑鎸囬拡錛屽垯涓嬮潰鐨勮〃杈懼紡鍙鍒跺瓧絎︿覆鐨勫湴鍧鑰屼笉鏄瓧絎︿覆鏈韓銆?/p>

pts1 = pts2;

濡傛灉浣犵‘瀹炲笇鏈涘鍒跺瓧絎︿覆錛岄偅涔堝彲浠ヤ嬌鐢╯trcpy ()鍑芥暟銆?/p>

//copy1.c strcpy ()紺轟緥
#include <stdio.h>
#include <string.h> //澹版槑strcpy ()鍑芥暟
#define SIZE 40
#define LIM 5
 
int main (void)
{
    
char qwords[LIM][SIZE];
    
char temp[SIZE];
    
int i = 0;
 
    
printf ("Enter %d words beginning with q:\n", LIM);
    
while (i < LIM && gets(temp))
    
{
        
if (temp[0] != 'q')
        
{
            
printf ("%s doesn't begin with q!\n", temp);
        
}
        
else
        
{
            
strcpy (qwords[i], temp);
            
i++;
        
}       
    
}
    
puts ("Here are the words accepted:");
    
for (i=0; i < LIM; i++)
    
{
        
puts (qwords[i]);
    
}
 
    
return 0;
}

璇鋒敞鎰忓彧鏈夊綋杈撳叆鐨勫崟璇嶉氳繃浜唓鍒ゆ柇錛岃鏁板糹鎵嶄細澧炲姞銆?br>榪欓噷浣跨敤浜嗕竴涓熀浜庡瓧絎︾殑鍒ゆ柇

if (temp[0] != 'q')

榪欑浉褰撲簬

if (strncmp (temp, "q", 1) != 0)

娉ㄦ剰鍦紝strcpy 涓や釜鍙傛暟涓紝絎簩涓弬鏁皌emp鎸囧悜鐨勫瓧絎︿覆琚鍒跺埌絎竴涓弬鏁皅word[i]鎵鎸囧悜鐨勬暟緇勪腑銆?br>temp琚О涓烘簮瀛楃涓詫紝qword琚О涓虹洰鏍囧瓧絎︿覆銆?br>涓轟粈涔堣榪欎箞璁捐錛屼負浠涔堜笉璁捐鍒板墠闈紵
濡傛灉娉ㄦ剰鍒板畠鍜岃祴鍊艱鍙ョ殑欏哄簭涓鏍鳳紝鐩爣鍦ㄥ乏杈癸紝灝卞緢瀹規槗璁頒綇鍙傛暟鐨勯『搴忋?/p>

3.strcpy ()鐨勫叾瀹冪壒鎬?br>棣栧厛錛屽畠鏄竴涓猚har *綾誨瀷錛屽畠榪斿洖鐨勬槸絎竴涓弬鏁扮殑鍊箋?br>絎簩錛岀涓涓弬鏁頒笉闇瑕佹寚鍚戞暟緇勭殑寮濮嬶紝榪欐牱灝卞彲浠ュ彧澶嶅埗鏁扮粍鐨勪竴閮ㄥ垎銆?/p>

//copy2.c
#include <stdio.h>
#include <string.h>
#define WORDS "beast"
#define SIZE 40
 
int main (void)
{
    
char *orig = WORDS;
    
char copy[SIZE] = "Be the best that you can be.";
    
char *ps;
 
    
puts (orig);
    
puts (copy);
    
ps = strcpy (copy + 7, orig);
    
puts (copy);
    
puts (ps);
 
    
return 0;
}

娉ㄦ剰ps鎸囧悜copy鐨勭8涓厓绱狅紝榪欐槸鍥犱負絎竴涓弬鏁版槸copy + 7銆?/p>

4. strncpy ()
strcpy ()鐨勭己鐐規樉鑰屾槗瑙侊紝瀹冧笉媯鏌ョ洰鏍囧瓧絎︿覆鏄惁鑳藉綰沖緱涓嬫簮瀛楃涓層?br>strncpy ()浼氱敤絎笁涓弬鏁版寚鏄庢渶澶у彲澶嶅埗鐨勫瓧絎︽暟銆?/p>

//copy3.c strncpy ()紺轟緥
#include <stdio.h>
#include <string.h> //澹版槑strcpy ()鍑芥暟
#define SIZE 40
#define TARGSIZE 7
#define LIM 5
 
int main (void)
{
    
char qwords[LIM][TARGSIZE];
    
char temp[SIZE];
    
int i = 0;
 
    
printf ("Enter %d words beginning with q:\n", LIM);
    
while (i < LIM && gets(temp))
    
{
        
if (temp[0] != 'q')
        
{
            
printf ("%s doesn't begin with q!\n", temp);
        
}
        
else
        
{
            
strncpy (qwords[i], temp, TARGSIZE - 1);
            
qwords[i][TARGSIZE-1] = '\0';
            
i++;
        
}       
    
}
    
puts ("Here are the words accepted:");
    
for (i=0; i < LIM; i++)
    
{
        
puts (qwords[i]);
    
}
 
    
return 0;
}

娉ㄦ剰錛屽湪榪欓噷鍑芥暟澶嶅埗鐨勫瓧絎︿覆鍙兘鏈鍚庢病鏈夌┖瀛楃錛屾墍浠ヤ綘蹇呴』鎵嬪姩鍦ㄦ渶鍚庢斁緗竴涓┖瀛楃錛岃屼笖娉ㄦ剰榪欓噷鏄鍒秐涓瓧絎﹁繃鍘伙紝鎵浠ヨ鐣欎竴涓粰絀哄瓧絎?/p>

錛屾墍浠ュ湪榪欓噷鏄疶ARGSIZE - 1;

strncpy (qwords[i], temp, TARGSIZE - 1);
qwords[i][TARGSIZE-1] = '\0';

5.sprintf ()鍑芥暟
sprintf ()鍑芥暟鏄湪stdio.h鑰屼笉鏄湪string.h涓0鏄庣殑銆?br>瀹冪殑浣滅敤鍜宲rintf ()涓鏍鳳紝浣嗘槸瀹冨啓鍒板瓧絎︿覆閲岃屼笉鏄啓鍒拌緭鍑烘樉紺恒?br>瀹冩彁渚涗簡鎶婂嚑涓厓绱犵粍鍚堟垚涓涓瓧絎︿覆鐨勪竴縐嶉斿緞銆?br>sprintf ()鐨勭涓涓弬鏁版槸鐩爣瀛楃涓插湴鍧銆?/p>

//format.c
#include <stdio.h>
#define MAX 20
 
int main (void)
{
    
char first[MAX];
    
char last[MAX];
    
char formal[2 * MAX + 10];
    
double prize;
 
    
puts ("Enter your first name: ");
    
gets (first);
    
puts ("Enter your last name: ");
    
gets (last);
    
puts ("Enter your prize money: ");
    
scanf ("%1f", prize);
    
sprintf (formal, "%s, %-19s: $%6.2f\n", last, first, prize);
    
puts (formal);
 
    
return 0;
}

6.鍏跺畠瀛楃涓插嚱鏁?/p>

char *strcpy (char * s1, const char * s2);

璇ュ嚱鏁版妸s2鎸囧悜鐨勫瓧絎︿覆(鍖呮嫭絀哄瓧絎?澶嶅埗鍒皊1鎸囧悜鐨勪綅緗紝榪斿洖鍊兼槸s1銆?/p>

char *strncpy (char * s1, const char *s2, size_t n);

璇ュ嚱鏁版妸s2鎸囧悜鐨勫瓧絎︿覆(鍖呮嫭絀哄瓧絎?澶嶅埗鍒皊1鎸囧悜鐨勪綅緗紝澶嶅埗鐨勫瓧絎︽暟涓嶈秴榪噉涓傝繑鍥炲兼槸s1銆?br>絀哄瓧絎﹀悗鐨勫瓧絎︿覆涓嶈澶嶅埗銆?br>濡傛灉婧愬瓧絎︿覆鐨勫瓧絎︽暟灝忎簬n涓紝鍦ㄧ洰鏍囧瓧絎︿覆涓氨浠ョ┖瀛楃濉厖銆?br>濡傛灉婧愬瓧絎︿覆鐨勫瓧絎︽暟澶т簬鎴栫瓑浜巒涓紝絀哄瓧絎﹀氨涓嶈澶嶅埗銆傝繑鍥炲兼槸s1銆?/p>

char *strcat (char *s1, const char *s2);

s2鎸囧悜鐨勫瓧絎︿覆(鍖呮嫭絀哄瓧絎?澶嶅埗鍒皊1鎸囧悜鐨勭粨灝俱傚鍒惰繃鏉ョ殑s2瑕嗙洊浜唖1鐨勭┖瀛楃銆傝繑鍥炲間負s1銆?/p>

char *strncat (char *s1, const char *s2);

s2鎸囧悜鐨勫瓧絎︿覆涓殑鍓峮涓瓧絎?鍖呮嫭絀哄瓧絎?澶嶅埗鍒皊1鎸囧悜鐨勭粨灝俱傚鍒惰繃鏉ョ殑s2瑕嗙洊浜唖1鐨勭┖瀛楃銆?br>s2瀛楃涓蹭腑鐨勭┖瀛楃鍙婂叾鍚庣殑浠諱綍瀛楃閮戒笉浼氳澶嶅埗錛屽茍涓旇拷鍔犱竴涓┖瀛楃鍒版墍寰楃粨鏋滃悗闈€?br>榪斿洖鍊間負s1銆?/p>

int strcmp (const char *s1, const char *s2);

濡傛灉s1瀛楃涓插湪鏈哄櫒緙栫爜欏哄簭涓惤鍚庝簬s2瀛楃涓詫紝鍑芥暟鐨勮繑鍥炲兼槸涓涓鏁幫紱濡傛灉涓や釜瀛楃涓茬浉鍚岋紝榪斿洖鍊兼槸0;
濡傛灉絎竴涓瓧絎︿覆鍦ㄦ満鍣ㄧ紪鐮侀『搴忎腑鍏堜簬絎簩涓瓧絎︿覆錛岃繑鍥炲兼槸涓涓礋鏁般?/p>

int strncmp (const char *s1, const char *s2);

璇ュ嚱鏁頒綔鐢ㄥ拰strcmp ()涓鏍鳳紝鍙槸姣旇緝n涓瓧絎﹀悗鎴栬呴亣瑙佺涓涓┖瀛楃鏃朵細鍋滄姣旇緝銆?/p>

char *strchr (const char *s1, int c);

璇ュ嚱鏁拌繑鍥炰竴涓寚鍚戝瓧絎︿覆s涓瓨鏀懼瓧絎鐨勭涓涓綅緗殑鎸囬拡(鏍囧織緇撴潫鐨勭┖瀛楃鏄瓧絎︿覆鐨勪竴閮ㄥ垎錛屽洜姝や篃鍙互鎼滅儲鍒板畠)銆?br>濡傛灉娌℃湁鎵懼埌璇ュ瓧絎︼紝鍑芥暟灝辮繑鍥炵┖鎸囬拡銆?/p>

char *strpbrk (const char *s1, const char *s2);

璇ュ嚱鏁拌繑鍥炰竴涓寚閽堬紝鎸囧悜瀛楃涓瞫1涓瓨鏀緎2瀛楃涓茬殑浠諱綍瀛楃鐨勭涓涓綅緗傚鏋滄病鏈夋壘鍒拌瀛楃銆傚鏋滄病鎵懼埌浠諱綍瀛楃錛岃繑鍥炵┖鎸囬拡銆?/p>

char *strrchr (const char * s, int c);

璇ュ嚱鏁拌繑鍥炰竴涓寚閽堬紝鎸囧悜瀛楃涓瞫涓瓧絎鏈鍚庝竴嬈″嚭鐜扮殑鍦版柟銆?鏍囧織緇撴潫鐨勭┖瀛楃鏄瓧絎︿覆鐨勪竴閮ㄥ垎錛屽洜姝や篃鍙互鎼滅儲鍒板畠)銆?br>濡傛灉娌℃湁鎵懼埌璇ュ瓧絎︼紝鍑芥暟灝辮繑鍥炵┖鎸囬拡銆?/p>

char *strstr (const char *s1, const char *s2)

璇ュ嚱鏁拌繑鍥炰竴涓寚閽堬紝鎸囧悜s1瀛楃涓蹭腑絎竴嬈″嚭鐜皊2瀛楃涓茬殑鍦版柟銆傚鏋滃湪s1涓病鎵懼埌s2瀛楃涓詫紝鍑芥暟灝辮繑鍥炵┖鎸囬拡銆?/p>

size_t strlen (const char *s);

榪斿洖瀛楃涓茬殑闀垮害銆?/p>

綆鍗曞簲鐢細
鍦ㄧ敤fgets ()鍑芥暟鏃訛紝璇誨彇涓琛岃緭鍏ワ紝榪欎釜鍑芥暟鎶婃崲琛岀瀛樺偍鍒扮洰鏍囧瓧絎︿覆涓?br>鎴戜滑鍙互浣跨敤strchr ()鍑芥暟鏉ョ敤涓涓┖瀛楃鏇挎崲榪欎釜鎹㈣絎︺?/p>

char line [80];
char * find;
 
fgets (line, 80, stdin);
find = strchr (line, '\n');
if (find)
{
    *
find = '\0';
}


]]>
瀛楃涓插嚱鏁?浜?http://www.shnenglu.com/k71983/archive/2008/05/06/48999.html鑱傚厓鏈?/dc:creator>鑱傚厓鏈?/author>Tue, 06 May 2008 06:10:00 GMThttp://www.shnenglu.com/k71983/archive/2008/05/06/48999.htmlhttp://www.shnenglu.com/k71983/comments/48999.htmlhttp://www.shnenglu.com/k71983/archive/2008/05/06/48999.html#Feedback0http://www.shnenglu.com/k71983/comments/commentRss/48999.htmlhttp://www.shnenglu.com/k71983/services/trackbacks/48999.html瀛楃涓插嚱鏁?浜?
1.鏍囧噯搴撲腑fgets ()鍜?fputs ()鐨勫疄鐜板熀鏈畻娉?/p>
// fgets ()鍑芥暟:浠巌op鎸囧悜鐨勬枃浠朵腑鏈澶氳鍙杗-1涓瓧絎︼紝鍐嶅姞涓婁竴涓狽ULL
char *fgets (char *s, int n, FILE *iop)
{
    
register int c;
    
register char *cs;
 
    
cs = s;
    
while (--n > 0 && (c = getc(iop)) != EOF)
    
{
        
if ((*cs++ = c) == '\n')
        
{
            
break;
        
}
    
}
    *
cs = '\0';
    
    
return (c == EOF && cs == s) ? NULL : s;
}


// fputs 鍑芥暟:灝嗗瓧絎︿覆s杈撳嚭鍒癷op鎸囧悜鐨勬枃浠朵腑
int fputs (char *s, FILE *iop)
{
    
int c;
    
    
while (c = *s++)
    
{
        
putc (c, iop);
    
}
    
    
return ferror(iop) ? EOF : 闈炶礋鍊?
}


]]>
久久久久国产精品| 久久夜色精品国产噜噜麻豆| 91精品国产91久久| 久久久久亚洲av成人无码电影 | 伊人久久大香线焦综合四虎| 日本三级久久网| 亚洲AV日韩AV天堂久久| 亚洲午夜久久久精品影院 | 久久久久久曰本AV免费免费| 久久精品视频网| 亚洲va久久久噜噜噜久久天堂 | 精品久久久久中文字幕一区| 久久久无码精品亚洲日韩按摩| 99久久精品国产一区二区蜜芽| 一本久久a久久精品vr综合| 欧美激情精品久久久久久久九九九| 伊人色综合久久天天人手人婷 | 久久精品亚洲一区二区三区浴池 | 久久精品国产半推半就| 少妇无套内谢久久久久| 99久久国产综合精品五月天喷水 | 久久久久人妻一区精品色 | 亚洲日韩中文无码久久| 欧美久久一级内射wwwwww.| 精品免费tv久久久久久久| 精品综合久久久久久98| 久久综合鬼色88久久精品综合自在自线噜噜| 久久伊人精品青青草原高清| 欧美午夜精品久久久久免费视| 亚洲午夜精品久久久久久app| 国产成人无码精品久久久久免费 | 国产精品久久久久久福利69堂| 亚洲人成网亚洲欧洲无码久久| 亚洲国产成人精品91久久久| 久久性精品| 久久香综合精品久久伊人| 欧美久久久久久| 久久人人爽人人爽人人AV东京热 | 欧美久久综合性欧美| 国产99久久久国产精免费| 欧洲性大片xxxxx久久久|