English 中文(简体)
Name of C/C++ stdlib naming convention?
原标题:

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?

问题回答

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.

The C standard library has well defined rules you must follow to avoid name conficts. I don t know anything about C++ though.

If you think this is a mess you should check out the PHP library...

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.

The sad truth is - there is no real convention.

See the argument order of stdio functions as a painful reminder.

I don t have the answer, but at least, I don t think that C and C++ use the same naming convention.

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签