What are the most common naming conventions in C?

前端 未结 11 2391
走了就别回头了
走了就别回头了 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:40

    Well firstly C doesn't have public/private/virtual functions. That's C++ and it has different conventions. In C typically you have:

    • Constants in ALL_CAPS
    • Underscores to delimit words in structs or function names, hardly ever do you see camel case in C;
    • structs, typedefs, unions, members (of unions and structs) and enum values typically are in lower case (in my experience) rather than the C++/Java/C#/etc convention of making the first letter a capital but I guess it's possible in C too.

    C++ is more complex. I've seen a real mix here. Camel case for class names or lowercase+underscores (camel case is more common in my experience). Structs are used rarely (and typically because a library requires them, otherwise you'd use classes).

提交回复
热议问题