日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C代码中的命名方式总结和改进

發(fā)布時間:2024/4/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C代码中的命名方式总结和改进 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
  • 宏全部使用大寫字母--------宏大寫
  • 結(jié)構(gòu)體名字全部使用typedef,typedef之后的名字為大寫-------結(jié)構(gòu)體別名大寫
  • 函數(shù)名全部使用小寫字母,單詞之間使用下劃線分割-------函數(shù)名小寫,單詞之間下劃線(1)
  • 函數(shù)名第一個單詞全小寫,后面單詞的首字母大寫,單詞之間使用下劃線---------函數(shù)名首單詞小寫,后面單詞首字母大寫(2)
  • 變量名也是全部使用小寫,單詞之間使用下劃線分割-------變量名小寫,單詞之間下劃線(1)
  • 變量名第一個單詞全小寫,后面單詞的首字母大寫,單詞之間使用下劃線---------變量名單詞小寫,后面單詞首字母大寫(2)
  • 變量的命名前后綴規(guī)則如下(這是匈牙利命名法的前后綴格式,以后其他地方使用上述的總結(jié),前后綴使用匈牙利的):

    The type prefix indicates the data type of the variable.

    Type prefixMeaningExample
    bbooleanbool bHasEffect;
    c (or none*)classCreature cMonster;
    chchar (used as a char)char chLetterGrade;
    ddouble, long doubledouble dPi;
    eenumColor eColor;
    ffloatfloat fPercent;
    nshort, int, long
    char used as an integer
    int nValue;
    sstructRectangle sRect;
    strC++ stringstd::string strName;
    szNull-terminated stringchar szName[20];

    The following type modifiers are placed before the prefix if they apply:

    Type modifierMeaningExample
    aarray on stackint anValue[10];
    ppointerint* pnValue;
    padynamic arrayint* panValue = new int[10];
    rreferenceint rnValue;
    uunsignedunsigned int unValue;

    The following scope modifiers are placed before the type modifier if they apply:

    Scope modifierMeaningExample
    g_global variableint g_nGlobalValue;
    m_member of classint m_nMemberValue;
    s_static member of classint s_nValue;

    補充:

    • p ---------for a pointer. A pfoo would be a pointer to data item of type FOO
    • pp------- for a pointer to a pointer.
    • h --------for a heap handle. This is a pointer to a pointer that points at a data item recorded within a heap.
    • rg -------for an unstructured array containing data items of a certain data type. An rgfoo would be an array that contains data of type foo. Individual elements would be selected by an ifoo index variable.
    • mp -------for an array which is used to map from one data type to another.Eg. A mpdochdod would be indexed via a doc index. The expression mpdochdod[doc] would produce a handle to a document descriptor.
    • dn-------- for an array whose elements that describes a meaningful index such as an opcode. If the meaningful index were an OP type, a data structure of type EOP (entries for OP) would be defined, and a dnop array would be defined which describes what each individual op means

    Max - added to an index data instance which records the actual size of an array or data block.
    eg. the declaration of a an array of type FOO in C would be:
    FOO rgfoo[ifooMax];

    Mac - added to an index data instance to indicate the limit of an actual usage within an array.Mac stands for current maximum. It is invariant that ifooMac <= ifooMax. ifooMac == ifooMax is the condition which is true when all entries within an array are in use.

    First - added to an index or pointer which designates the first element within a range that may be validly processed

    Last - added to an index or pointer which designates that last entry within a range that may be validly processed.

    Lim - stands for limit. An ifooLim is equal to ifooLast + 1 and designates the location where a new foo item could be recorded in an array or data block.



    轉(zhuǎn)載于:https://www.cnblogs.com/jack204/archive/2011/09/07/2170408.html

    總結(jié)

    以上是生活随笔為你收集整理的C代码中的命名方式总结和改进的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。