zoukankan      html  css  js  c++  java
  • 区分保留字跟关键字

    李维的<Inside VCL>.书中第一章中举的第一个console程序中有以下的函数声明:

    function WindowProc(Window:HWND;AMessage:UINT;WParam:WPARAM;LParam:LPARAM):LRESULT;stdcall;export;

    不知道你想过一个问题没:在Delphi中是不区分大小写的,也就是说这里的声明中变量名和类型名相同了.而我们在学Pascal,C/C++的时候,老师常对我们说不能去关键字作为变量名,为什么这里又能使用呢?

    看到这里的时候很困惑,所以查看了Dephi7的<Delphi Language Guide>,终于找到了答案:那就是保留字(Directives)跟关键字(Reserved words)的区别.

    在<Delphi Language Guide>中提到:The following reserved words cannot be redefined or used as identifiers.也就是说关键字是不能作为变量名的.书中对保留字的说明如下:

    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.也就是说保留字则是可以用作变量名的.

    这就解释了为什么在前面的函数声明中允许出现WParam:WPARAM;这种声明.顺便说一下的是李维在<Inside VCL>一书中的第31页小字解说部分说"C/C++ Builder为了更好的执行效率而使用了关键字message来分派窗口消息...",这里关键字应该改为保留字才对,因为Message是保留字而非关键字.我们在阅读VCL的源代码时也常可以看到用Message作为变量名的.

  • 相关阅读:
    一笔画问题(搜索)
    Sum
    js获取时间日期
    [Hibernate 的left join]Path expected for join!错误
    关于firefox下js中动态组装select时指定option的selected属性的失效
    mooltools扩展之前已经定义好的方法和json数据
    HttpSession, ActionContext, ServletActionContext 区别
    japidcontroller自动绑定的数据类型
    ConcurrentModificationException
    Hibernate中使用COUNT DISTINCT
  • 原文地址:https://www.cnblogs.com/feng801/p/1334961.html
Copyright © 2011-2022 走看看