Naming scheme for typedefs

后端 未结 2 1498
猫巷女王i
猫巷女王i 2020-12-06 07:22

I\'m working on a library that extensively used constructs like

typedef struct foo_bar_s {
    ...
} foo_bar_t;

It\'s a bad idea to use the

相关标签:
2条回答
  • 2020-12-06 07:48

    Although, "_t" is reserved, it is very unlikely that you will encounter a problem. However, this convention is a remnant of older versions of C where this syntax was required in order to name structs, and so nowadays you can simply write something like the following (omitting the typedef and the typedef names):

    struct name_of_struct
    {
       type1 member1;
       type2 member2;
       // ...
       typeN memberN;
    };
    

    And yes, you can use single line comments ("//...") in the current standard of C.

    0 讨论(0)
  • 2020-12-06 08:06

    I use the naming conventions used in Dave Hanson's C Interfaces and Implementations: a type is named with the module name and a capital T. So for example, the type of sequences is Seq_T, and the type of hash tables is Table_T. Within the implementation of a module Hanson uses #define to abbreviate just to T. This is basically Modula-3 conventions applied to C programming, but I find that after a brief initial shock it works well.

    0 讨论(0)
提交回复
热议问题