By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

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

P: 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;

Regards
Raman Chalotra

Jan 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: 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.
Jan 24 '07 #2

P: n/a
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
Jan 24 '07 #3

P: 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 */
#else
#define __restrict /* ...but not in older C. */
#endif

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;
--
Regards,
Hallvard
Jan 24 '07 #4

P: 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
__restrict__

The first one is a feature of Microsoft C

__restrict

I quote the documentation in
http://msdn2.microsoft.com/en-us/library/5ft82fed.aspx
< 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 gcc.info:
< quote>
gnu++98
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.
Jan 24 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.