Can anyone tell me what the purpose of C functions which start with "__" ? Also another question is the same use of the "__" in defines like #define __HTTP_VERB_GET "GET"

Recommended Answers

All 3 Replies

>Can anyone tell me what the purpose of C functions which start with "__" ?

It's customary for compiler to name their functions and macros starting with some "_" or "__" in order to make it harder for an user define function to conflict in naming.
It's recomended that you don't use those character to name your own created functions.

>Also another question is the same use of the "__" in defines like #define __HTTP_VERB_GET "GET"

The precompiler will sustitute GET every time that it will see it, for __HTTP_VERB_GET; which will be declared somewhere in a header file.

To elaborate:

>Can anyone tell me what the purpose of C functions which start with "__" ?

It's customary for compiler to name their functions and macros starting with some "_" or "__" in order to make it harder for an user define function to conflict in naming.
It's recomended that you don't use those character to name your own created functions.

As a matter of fact, identifiers that begin with an underscore followed by another underscore or an uppercase letter are reserved for the implementation, that is, for the compiler. You shouldn't use names like these at all, on the off chance that some compiler has also used the very same name.

There are no such restrictions on these characters in the middle of identifiers. an__identifier and my_Name are perfectly acceptable.

It should be noted that functions and types and identifiers declared with double underscores or _X are likely specific to the compiler. This means that if your code uses these functions it likely won't be very portable. There are exceptions, of course. mkdir() is a very common UNIX function, and MSVC declares it as _mkdir().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.