1

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).

Community
  • 1
  • 1
Raphael
  • 1,847
  • 1
  • 17
  • 29
  • 2
    The convention currently used in the project/organization or, failing such [mandated] guidance, personal preference and comfort. (To answer the "used by most" question research and collecting data adequately representing C programmers and their styles would need to be taken; SO is not the place.) –  Sep 21 '11 at 20:53

3 Answers3

3

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.

eyesathousand
  • 587
  • 2
  • 10
0

Depends, e.g. if you write code in the linux kernel use snake_case. See coding guidelines for the kernel.

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
0

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.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631