Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,__const pthread_mutexattr_t *__restrict__mutex_attr) __THROW;

Thread Tools

extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,__const pthread_mutexattr_t *__restrict__mutex_attr) __THROW;

Posts: n/a
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;

Raman Chalotra

Reply With Quote
Ian Collins
Posts: n/a
Raman wrote:
> Hi All,
> The declaration of pthread_mutex_init in pthread.h is as in pthread.h

Of topic here, but it looks very platform specific and more than a
little broken. Try a group for your platform.

Ian Collins.
Reply With Quote
Dave Vandervies
Posts: n/a
In article <(E-Mail Removed). com>,
Raman <(E-Mail Removed)> wrote:
>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

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 Vandervies Removed)
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
Reply With Quote
Hallvard B Furuseth
Posts: n/a
Raman writes:
> 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.

These are not from the C standard, but some library- or compiler-
specific header file tricks.

Some of these are macros, you'll find the definitions in some other
header file. This looks like some gcc or glibc thing, if so you can run
gcc -E <program.c> | less
to see what the declaration expands to.

The initial '__'s are to put the identifiers in the implementation's
namespace. (The C standard reserves identifiers starting with '__' for
the implementation.) Likely some included file does something like

#if __STDC_VERSION__ >= 199901L /* C99 standard or later */
#define __restrict restrict /* 'restrict' is a keyword in C99 */
#define __restrict /* ...but not in older C. */

The 'restrict' qualifier is a C99 thing which means all of a function's
accesses to the object which the variable points to, will go through
that pointer or a pointer derived from it. (Rather than from some other
variable.) This allows the compiler to do some optimizations.

__THROW in glibc makes use of a gcc extension: when compiled with gcc it
expands to attribute((nothrow)), which according to the gcc manual
informs the compiler that the function cannot throw an exception.

> extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,
> __const pthread_mutexattr_t *__restrict
> __mutex_attr) __THROW;

Reply With Quote
jacob navia
Posts: n/a
Raman a écrit :
> 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;
> Regards
> Raman Chalotra

There is a "restrict" keyword in C. Since not all compilers support it,
this is probably a macro that will expand to restrict if the
compiler supports it, to nothing if there is no support for it.

That *could* be the reason.

Now there is a

__restrict and

The first one is a feature of Microsoft C


I quote the documentation in
< quote >
Like the restrict __declspec modifier, the __restrict keyword indicates
that a symbol is not aliased in the current scope. The __restrict
keyword differs from the restrict __declspec modifier in the following ways:

The __restrict keyword is valid only on variables, and
__declspec(restrict) is only valid on function declarations and definitions.

When __restrict is used, the compiler will not propagate the
no-alias property of a variable. That is, if you assign a __restrict
variable to a non-__restrict variable, the compiler will not imply that
the non-__restrict variable is not aliased.

Generally, if you affect the behavior of an entire function, it is
better to use the __declspec than the keyword.

__restrict is similar to restrict from the C99 spec, but __restrict can
be used in C++ or C programs.

< end quote >

For gcc:
I quote from
< quote>
The same as -std=c++98 plus GNU extensions. This is the
default for C++ code.

Even when this option is not specified, you can still use some of
the features of newer standards in so far as they do not conflict
with previous C standards. For example, you may use "__restrict__"
even when -std=c99 is not specified.

< end quote >

The other keywords like __const are probably similar

The __THROW macro means probably that the procedures executes a non
local jump, i.e. a throw when an exception is raised.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
extern int *a , int a[10] sinbad C Programming 6 08-10-2007 07:32 PM
extern const char * vs. extern const char [] Thomas Matthews C++ 5 08-02-2004 10:36 AM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM