• 内核开发0 --- 代码规范


    注释

    使用/* */ 不要使用//

    宏定义需要大写,函数宏可以小写

    typedef

    不要对结构体和指针使用typedef

    Please don't use things like ``vps_t``.
    It's a **mistake** to use typedef for structures and pointers. When you see a
    
    .. code-block:: c
    
    
    	vps_t a;
    
    in the source, what does it mean?
    In contrast, if it says
    
    .. code-block:: c
    
    	struct virtual_container *a;
    
    you can actually tell what ``a`` is.
    
    Lots of people think that typedefs ``help readability``. Not so. They are
    useful only for:
    
     (a) totally opaque objects (where the typedef is actively used to **hide**
         what the object is).
    
         Example: ``pte_t`` etc. opaque objects that you can only access using
         the proper accessor functions.
    
         .. note::
    
           Opaqueness and ``accessor functions`` are not good in themselves.
           The reason we have them for things like pte_t etc. is that there
           really is absolutely **zero** portably accessible information there.
    
     (b) Clear integer types, where the abstraction **helps** avoid confusion
         whether it is ``int`` or ``long``.
    
         u8/u16/u32 are perfectly fine typedefs, although they fit into
         category (d) better than here.
    
         .. note::
    
           Again - there needs to be a **reason** for this. If something is
           ``unsigned long``, then there's no reason to do
    
    	typedef unsigned long myflags_t;
    
         but if there is a clear reason for why it under certain circumstances
         might be an ``unsigned int`` and under other configurations might be
         ``unsigned long``, then by all means go ahead and use a typedef.
    
     (c) when you use sparse to literally create a **new** type for
         type-checking.
    
     (d) New types which are identical to standard C99 types, in certain
         exceptional circumstances.
    
         Although it would only take a short amount of time for the eyes and
         brain to become accustomed to the standard types like ``uint32_t``,
         some people object to their use anyway.
    
         Therefore, the Linux-specific ``u8/u16/u32/u64`` types and their
         signed equivalents which are identical to standard types are
         permitted -- although they are not mandatory in new code of your
         own.
    
         When editing existing code which already uses one or the other set
         of types, you should conform to the existing choices in that code.
    
     (e) Types safe for use in userspace.
    
         In certain structures which are visible to userspace, we cannot
         require C99 types and cannot use the ``u32`` form above. Thus, we
         use __u32 and similar types in all structures which are shared
         with userspace.
    
    Maybe there are other cases too, but the rule should basically be to NEVER
    EVER use a typedef unless you can clearly match one of those rules.
    
    In general, a pointer, or a struct that has elements that can reasonably
    be directly accessed should **never** be a typedef.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79

    控制访问性

    不被导出的函数和变量必须声明为静态的

  • 相关阅读:
    java,springboot钉钉开发连接器,自定义连接器配合流程使用,流程加入连接器,连接器发送参数,然后你本地处理修改值,返回给流程
    vue基本使用1
    MySQL索引的分类
    一款基于.Net开发、开源、支持多平台云存储文件管理器
    【计算机毕业设计】JAVA SpringBoot少儿编程课程管理网站
    Spring Cloud Alibaba x AppActive 带来的全新异地活动解决方案
    数据库安全策略与实施措施
    穿越障碍:最小路径和的高效算法比较【python力扣题64】
    关于爬虫中的hook(defineProperty,hook cookies, hook载荷数据,hookXHR)
    【网络安全】网络攻击的类型有哪些?
  • 原文地址:https://blog.csdn.net/weixin_43604927/article/details/126679297