user-0 提问: linux下的代码变量命名，求助

回复:
user: user-1
content: 如果你是从Java来的，那么 public class Persion {} Person person; 你会觉得很自然，但真的如此么？ 如果有两个person怎么办？ 所以仔细想想，好的命名应该是person1/person2或者personA/personB， 更好的命名应该是Person LZ; Person me; Person bill; Person alice;这样的有具体含义的。 所以对于struct test; 我更倾向于struct test a;就和int a;一样，对于没有特定意义/含义的，给它个不确切的名字。 相比之下struct test _test已经算是很好的命名了，当然更推荐更有意义的名字。  int a; void a(); 冲突嘛？只要编译器认得出来，就不冲突，用来回答你第二个问题。

user: user-2
content: 引用 12 楼 ri_aje 的回复:[quote=引用 楼主 caddor9100 的回复:] 比如一个结构体  windows :  typdef  struct tagTest {  }Test, *PtrTest;  linux 呢? struct test {  };  linux 下推荐小写，卧槽，导致 结构体做函数参数的时候，相当蛋疼，都不知道怎么命名了。比如：  void fun(Test test); //windows  void fun(test _test);// 无奈之下，我只好加_ 可以直接写 void fun (test test); [/quote] 这招儿 C 语言不认，只能写 struct test test 了。 我见过的其他(c++)全小写命名法一般都是加 _t 后缀，或者加前缀 a_, an_ 之类的。

user: user-2
content: 引用 楼主 caddor9100 的回复:比如一个结构体  windows :  typdef  struct tagTest {  }Test, *PtrTest;  linux 呢? struct test {  };  linux 下推荐小写，卧槽，导致 结构体做函数参数的时候，相当蛋疼，都不知道怎么命名了。比如：  void fun(Test test); //windows  void fun(test _test);// 无奈之下，我只好加_ 可以直接写 void fun (test test);  引用 楼主 caddor9100 的回复:问题2：   struct column{ 	int            width; 	char           *label; 	char           *fmt; }*column = NULL;  *column这是什么鬼?  以前见过：  struct A {  }obj , *pA;  实例怎么可以和类型同名呢？ 先把基础打牢吧，赶上你这二把刀的， linux 也很无奈。

user: user-3
content: // Windows typedef struct _Test {     int _unused; } Test, *TestPtr;  void fun(Test *ptest);  // Linux  typedef struct _Test {     int _unused; } test_t;  void fun(test_t *ptest);

user: user-4
content: 引用 2 楼 zxh707wk 的回复:引用 1 楼 user-8 的回复:话说，变量命名号称编程的第一难题……确实 巴别塔

user: user-0
content: 引用 4 楼 jiqiang01234 的回复:可以用“驼峰”命名法，第一个单词的首字母小写，后面单词的首字母大写。如： int testNum; int getTestNum(); 引用 4 楼 jiqiang01234 的回复:可以用“驼峰”命名法，第一个单词的首字母小写，后面单词的首字母大写。如： int testNum; int getTestNum();    struct column{ int            width; char           *label; char           *fmt; }*column = NULL;  *column这是什么鬼?  以前只见过：  struct A {  }obj , *pA;  实例怎么可以和类型同名呢？

user: user-5
content: 可以用“驼峰”命名法，第一个单词的首字母小写，后面单词的首字母大写。如： int testNum; int getTestNum();

user: user-4
content: 参考Tiny C Compiler中相关源代码片断。

user: user-0
content: 引用 8 楼 zhao4zhong1 的回复:struct struct [tag] { member-list } [declarators];  [struct] tag declarators;  The struct keyword defines a structure type and/or a variable of a structure type. See Anonymous Structures and Unsized Array in a Structure for more information.  A structure type is a user-defined composite type. It is composed of "fields" or "members" that can have different types.  In C++, a structure is the same as a class except that its members are public by default.  Using a Structure  In C, you must explicitly use the struct keyword to declare a structure. In C++, this is unnecessary once the type has been defined.  You have the option of declaring variables when the structure type is defined by placing one or more comma-separated variable names between the closing brace and the semicolon.  For related information, see class, union, and enum.  Example 1  struct PERSON              // Declare PERSON struct type {    int   age;              // Declare member types    long  ss;    float weight;    char  name[25]; } family_member;           // Define object of type PERSON     struct PERSON sister;   // C style structure declaration    PERSON brother;         // C++ style structure declaration     sister.age  = 13;       // assign values to members    brother.age =  7; Structure variables can be initialized. The initialization for each variable must be enclosed in braces.  Example 2  struct POINT            // Declare POINT structure {    int x;               // Define members x and y    int y; } spot = { 20, 40 };    // Variable spot has                         //     values x = 20, y = 40 struct POINT there;     // Variable there has POINT type struct CELL             // Declare CELL bit field {    unsigned character  : 8;  // 00000000 ????????    unsigned foreground : 3;  // 00000??? 00000000    unsigned intensity  : 1;  // 0000?000 00000000    unsigned background : 3;  // 0???0000 00000000    unsigned blink      : 1;  // ?0000000 00000000 } screen[25][80];       // Array of bit fields  linux 内核代码里也有很多 结构体和实例同名的例子  擦，吃惊了。  这么蛋疼的 写法。

user: user-4
content: struct struct [tag] { member-list } [declarators];  [struct] tag declarators;  The struct keyword defines a structure type and/or a variable of a structure type. See Anonymous Structures and Unsized Array in a Structure for more information.  A structure type is a user-defined composite type. It is composed of "fields" or "members" that can have different types.  In C++, a structure is the same as a class except that its members are public by default.  Using a Structure  In C, you must explicitly use the struct keyword to declare a structure. In C++, this is unnecessary once the type has been defined.  You have the option of declaring variables when the structure type is defined by placing one or more comma-separated variable names between the closing brace and the semicolon.  For related information, see class, union, and enum.  Example 1  struct PERSON              // Declare PERSON struct type {    int   age;              // Declare member types    long  ss;    float weight;    char  name[25]; } family_member;           // Define object of type PERSON     struct PERSON sister;   // C style structure declaration    PERSON brother;         // C++ style structure declaration     sister.age  = 13;       // assign values to members    brother.age =  7; Structure variables can be initialized. The initialization for each variable must be enclosed in braces.  Example 2  struct POINT            // Declare POINT structure {    int x;               // Define members x and y    int y; } spot = { 20, 40 };    // Variable spot has                         //     values x = 20, y = 40 struct POINT there;     // Variable there has POINT type struct CELL             // Declare CELL bit field {    unsigned character  : 8;  // 00000000 ????????    unsigned foreground : 3;  // 00000??? 00000000    unsigned intensity  : 1;  // 0000?000 00000000    unsigned background : 3;  // 0???0000 00000000    unsigned blink      : 1;  // ?0000000 00000000 } screen[25][80];       // Array of bit fields

user: user-0
content: 引用 6 楼 zhao4zhong1 的回复:引用 2 楼 zxh707wk 的回复:[quote=引用 1 楼 user-8 的回复:] 话说，变量命名号称编程的第一难题……确实 巴别塔[/quote]  帮忙看看5楼，这个奇怪的语法，是开一个开源库里的，而且出现次数很多。

user: user-6
content: 命名并没有强制要求，仅仅属于个人习惯，好的习惯会给你带来很多好处而已；

user: user-7
content: 引用 1 楼 user-8 的回复:话说，变量命名号称编程的第一难题……确实

user: user-8
content: 话说，变量命名号称编程的第一难题……