計算機二級輔導(dǎo):區(qū)分保留字跟關(guān)鍵字

字號:

第一個console程序中有以下的函數(shù)聲明:
    function WindowProc(Window:HWND;AMessage:UINT;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;export;
    不知道你想過一個問題沒:在Delphi中是不區(qū)分大小寫的,也就是說這里的聲明中變量名和類型名相同了.而我們在學(xué)Pascal,C/C++的時候,老師常對我們說不能去關(guān)鍵字作為變量名,為什么這里又能使用呢?
    我剛開始看到這里的時候很困惑,所以我查看了Dephi7的,終于找到了答案:那就是保留字(Directives)跟關(guān)鍵字(Reserved words)的區(qū)別.
    在中提到:The following reserved words cannot be redefined or used as identifiers.也就是說關(guān)鍵字是不能作為變量名的.書中對保留字的說明如下:
    Directives are words that are sensitive in specific locations within source code. Deriectives have special meanings in the Delphi language,but unlike reserved words,appear only in contexts where user-defined identifiers cannot occured.Heance-although it is inadvisable to do so-you can define an identifier that looks exactly like a directive.也就是說保留字則是可以用作變量名的.  這就解釋了為什么在前面的函數(shù)聲明中允許出現(xiàn)WParam:WPARAM;這種聲明.順便說一下的是李維在一書中的第31頁小字解說部分說\"C/C++ Builder為了更好的執(zhí)行效率而使用了關(guān)鍵字message來分派窗口消息...\",這里關(guān)鍵字應(yīng)該改為保留字才對,因為Message是保留字而非關(guān)鍵字.我們在閱讀VCL的源代碼時也??梢钥吹接肕essage作為變量名的