Possible 开发者_运维知识库Duplicate:
What are the most common naming conventions in C?
Is there a official (or widely used) naming convention for the C language after all? One like Java's naming convention (UpperCamelCase
case for classes, lowerCamelCase
for methods, etc)?
I've seen many different conventions, like variable_name
, variableName
, variablename
, etc. Is there one that is used by most C programmers?
EDIT: Just to make it clearer, the question is if there is or there is not mostly used naming convention. Like one that programmers don't have to think about (like Java's, or C#'s).
In the style of the C standard:
Variable, function and struct naming schemes are undefined.
Use whatever style you prefer for your own new projects, keep consistent style within other codebases.
Personally I use camelCase - less use of shift and no annoying type encoding into variables, any decent IDE should be able to tell me what type a variable is.
Depends, e.g. if you write code in the linux kernel use snake_case. See coding guidelines for the kernel.
If you're working on existing code, follow the existing naming convention used in that code. The only thing worse than a bad naming convention is a mixture of inconsistent naming conventions. (The same applies to brace styles, indentation level, and so forth.)
If you're writing new code, I'd personally recommend looking at the sample code in K&R and the C standard, but it's up to you.
精彩评论