What are the most common naming conventions in C?

前端 未结 11 2355
走了就别回头了
走了就别回头了 2020-12-02 04:13

What are the naming conventions commonly use in C? I know there are at least two:

  1. GNU / linux / K&R with lower_case_functions
  2. ? name ? with UpperC
11条回答
  •  一整个雨季
    2020-12-02 04:35

    Coding in C#, java, C, C++ and objective C at the same time, I've adopted a very simple and clear naming convention to simplify my life.

    First of all, it relies on the power of modern IDEs (such as eclipse, Xcode...), with the possibility to get fast information by hovering or ctrl click... Accepting that, I suppressed the use of any prefix, suffix and other markers that are simply given by the IDE.

    Then, the convention:

    • Any names MUST be a readable sentence explaining what you have. Like "this is my convention".
    • Then, 4 methods to get a convention out of a sentence:
      1. THIS_IS_MY_CONVENTION for macros, enum members
      2. ThisIsMyConvention for file name, object name (class, struct, enum, union...), function name, method name, typedef
      3. this_is_my_convention global and local variables,
        parameters, struct and union elements
      4. thisismyconvention [optional] very local and temporary variables (such like a for() loop index)

    And that's it.

    It gives

    class MyClass {
        enum TheEnumeration {
            FIRST_ELEMENT,
            SECOND_ELEMENT,
        }
    
        int class_variable;
    
        int MyMethod(int first_param, int second_parameter) {
            int local_variable;
            TheEnumeration local_enum;
            for(int myindex=0, myindex

提交回复
热议问题