Reputation: 96859
I wonder if the naming convention used in C/C++ standard libraries has a name, or at least a cheat-sheet where I can lookup the rules. E.g.
push_back -- underscore used
setstate -- but not used here!
string::npos -- when to use abbreviations?
fprintf
...
Does the naming convention used in the C/C++ standard libraries have a specific name?
Upvotes: 35
Views: 10643
Reputation: 7434
The C standard library has well-defined rules you must follow to avoid name conflicts.
Upvotes: 10
Reputation: 753665
I don't think there is a name for either set of naming conventions.
The naming conventions in the C and C++ standards are different, though faintly related.
In particular, in the C library, no function or macro name contains an underscore (AFAICR), unlike the C++ library.
Most of the C library naming convention was controlled by precedent; it standardized existing practice (as of about 1984), with remarkably few inventions (locale handling via <locale.h>
being the main one).
The C++ library was based on precedent too - but a different set of precedents, and I think it is arguable that the STL was not in as widespread use prior to its adoption by the standard as the functions in the C library were.
Upvotes: 0
Reputation: 53289
C/C++ uses the famous make-stuff-up-as-we-go-along naming convention. In general, the only consistent things you can say about the C/C++ standard library naming convention is that it doesn't use camel case (except for C++ STL template typenames), it uses lower-case class and function names, and (sometimes) uses underscores to separate words. But the usage of underscores is more of a C++ thing; C in particular tends to abbreviate words, e.g. strlen
, memcpy
. This is probably a result of the tendency to use very terse names for things in the early days of UNIX.
Upvotes: 35
Reputation: 41331
I think there are several groups invented at different times by different people and using somewhat different conventions: C libraries, streams, strings, STL (containers + algorithms + iterators). I have a feeling that the latter might be seen as the convention, which sets the example for things like boost and C++0x naming.
Upvotes: 6
Reputation: 17750
I don't have the answer, but at least, I don't think that C and C++ use the same naming convention.
Upvotes: 0
Reputation: 273416
The sad truth is - there is no real convention.
See the argument order of stdio functions as a painful reminder.
Upvotes: 4