lynks
lynks

Reputation: 5689

C Library Double Underscore Confusion

I have read all the questions I can find about this, but nobody has yet addressed my confusion.

If I understand correctly, the use of a double underscore at the beginning of a method or variable name in library code is simply a namespace convention. It allows the operating system code to avoid clashing with any application code.

Why, then, does my /usr/include/string.h contain, for example, the following function declaration;

extern char *strcpy (char *__restrict __dest, __const char *__restrict __src)
    __THROW __nonnull ((1, 2));

Ignoring the __THROW and __nonnull ((1, 2)); parts, I have the following questions;

Clearly I've got my wires crossed somewhere along the line, if someone could clear this up for me that would be great.

Upvotes: 3

Views: 201

Answers (1)

Jens Gustedt
Jens Gustedt

Reputation: 78903

  • The parameter names are with __ such that they don't clash with macros that a program might have defined. Another option would have been to omit the parameter names completely from the declaration.
  • It is strcpy because that is the symbol (of the C library) that is declared here
  • The const and restrict keywords are protected in case somebody uses a compiler that doesn't implement them, yet.

Upvotes: 3

Related Questions