In article <11*********************@s48g2000cws.googlegroups. com>,
Raman <ra***********@gmail.comwrote:
>Hi All,
The declaration of pthread_mutex_init in pthread.h is as in pthread.h
Some one please explain. ( what is "__resrict", whay "__" before
"mutex" and what is __THROW.
extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
__const pthread_mutexattr_t *__restrict
__mutex_attr) __THROW;
The short answer is "You don't need to know, and you probably shouldn't
be looking in your header files and asking questions like this."
The slightly longer answer is "Any explanation is likely to involve
system-specific knowledge and is therefore beyond the scope of
comp.lang.c, so you should check with somebody who knows your
implementation".
There is, however, a long answer that's actually within the scope of CLC,
and here it is:
Any symbol beginning with "__" is reserved for the implementation's use
(as are most beginning with "_").
This means that (a) you're not allowed to use them, and if you do use
them and something breaks it's your fault; and (b) whoever wrote the
implementation is allowed to use them for whatever they want to, and is
guaranteed that this will not cause any conflicts with valid user code.
The names of the arguments (__mutex and __mutex_attr) are in the
implementor's namespace so that you can't break it by doing something
legal-but-silly like:
--------
#define mutex ); extern void do_something_strange(int i
#include <pthread.h>
--------
(which would cause any function prototype that used "mutex" as an
argument name to be incorrect without actually causing any easily
diagnosable errors).
If you try to do the same thing using __mutex instead, you're violating
the implementor's namespace, and they're allowed to laugh at you when
it breaks.
__restrict and __const are, if I'm correct, in places where the parser
would expect to see a type qualifier. I suspect that they're macros
that are conditionally defined to be either empty or some type qualifier
equivalent to const and restrict, respectively.
That leaves __THROW, which (like __const and __restrict) invokes some kind
of implementation magic, but I don't have a good explanation for what
that might be. My best guess is that if the header is being compiled
as C++ rather than C it's defined as a hint to the C++ compiler about
what if any exceptions the function can throw. (But see the short and
slightly longer answers I put at the top of this post.)
dave
--
Dave Vandervies
dj******@csclub.uwaterloo.ca
But if, by some strange chance, you are *not* writing a C compiler,
don't use the leading underscores.
--Richard Heathfield in comp.lang.c