473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
4 4372
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables....
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
4
by: Chad | last post by:
What purpose does __THROW serve in stdio.h. For example, in I see stuff like the following in stdio.h: /* Generate a temporary filename. */ extern char *tmpnam (char *__s) __THROW;...
2
by: Fei Liu | last post by:
Sorry if I am OT, It seems I cannot declare a per object ncwrite_lock in a C++ class. class C{ pthread_mutex_t ncwrite_lock; C () : ncwrite_lock(PTHREAD_MUTEX_INITIALIZER){} // error }; ...
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
4
by: CoL | last post by:
Hi All, I am working on a code that consumes third party libraries. My problem is extern int errno; is declared in one of those third party headers. This is causing conflict to the std. Linux...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.