常用接受的变量名格式 - C / C ++ [英] Commonly Accepted Variable Name Formatting - C/C++

查看:151
本文介绍了常用接受的变量名格式 - C / C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这可以是一个偏好的问题,但我注意到,在很多代码示例中我看到的变量名称有一个前缀 g _ s _ m _ ,或只是 _ 。这是一个普遍接受的做法,这些前缀是什么意思?是否还有其他人会很好知道?

解决方案


  • g_ 是一个全局变量

  • m _ 是成员(实例变量)

  • _


  • 这是很常见的,许多开发人员都知道它,虽然它不是(据我所知)普遍接受。



    更新:请在下面整合评论,以提高曝光率




    • _ 也可用于表示局部变量(这个变量实际上不是标准)

    • k 可用于表示常数


    I realize that this can be a matter of preference, but I have noticed that variables names in a lot of code samples I've seen have a prefix of g_, s_, m_, or just _. Is this a commonly accepted practice, and what do these prefixes mean? Are there any others that would be good to know?

    解决方案

    • g_ is a global variable
    • s_ is a static
    • m_ is a member (an instance variable)
    • _ is either a member, or more specifically a private member (both usages turn up)

    This is common enough that many developers know about it, although it is not (to my knowledge) universally accepted. I don't think you are missing any others.

    Update: Integrating comments below for better visibility

    • _ can also be used to denote a local variable (this one really isn't "standard")
    • k can be used to denote a constant

    这篇关于常用接受的变量名格式 - C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆