zoukankan      html  css  js  c++  java
  • C/C++里面的struct和typedef

    今天看到这样的代码

    typedef struct _Abc {
        uint64_t unit_id;
        ......
    } Abc;

    开始不理解这个的意思,后来看到这个解释:

    https://stackoverflow.com/questions/5558994/naming-convention-when-using-struct-in-c

    There is no benefit in user code, it's just ugly. In the second example, the HuffCode_ isn't even necessary since the struct type is already named by the typedef.
    
    The only places where this can be useful are:
    
    1. When StructName is already in use, StructName_ gives a different name (but you should really come up with a better name).
    2. Identifiers in the C standard library that are not defined by the standard shouldn't conflict with user code identifiers. Therefore, C library writers use the _ prefix in the hopes that users will not use that. Unfortunately, some users do.
    3. In very old compilers, it may be useful to give the struct a different name than is used in the typedef. You need both the typedef and the other name if you're building a linked structure (example).
  • 相关阅读:
    身份证的测试用例
    集合
    网易考拉测试面试题整理
    linux基本指令分类
    网络编程
    设计模式
    MySQL中的索引
    MySQL中的事务
    Java判断字符串是否为乱码
    Activiti6.x删除外键
  • 原文地址:https://www.cnblogs.com/charlesblc/p/7197156.html
Copyright © 2011-2022 走看看