extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,__const pthread_mutexattr_t *__re

Discussion in 'C Programming' started by Raman, Jan 24, 2007.

  1. Raman

    Raman Guest

    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
    Raman, Jan 24, 2007
    #1
    1. Advertising

  2. Raman

    Ian Collins Guest

    Re: extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,__constpthread_mutexattr_t *__restrict__mutex_attr) __THROW;

    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.
    Ian Collins, Jan 24, 2007
    #2
    1. Advertising

  3. In article <>,
    Raman <> 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
    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
    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
    Dave Vandervies, Jan 24, 2007
    #3
  4. Re: extern int pthread_mutex_init (pthread_mutex_t *__restrict__mutex,__const pthread_mutexattr_t *__restrict__mutex_attr) __THROW;

    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
    Hallvard B Furuseth, Jan 24, 2007
    #4
  5. Raman

    jacob navia Guest

    Re: extern int pthread_mutex_init (pthread_mutex_t *__restrict __mutex,__constpthread_mutexattr_t *__restrict__mutex_attr) __THROW;

    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.
    jacob navia, Jan 24, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Schnoffos
    Replies:
    2
    Views:
    1,198
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,615
    Old Wolf
    Jan 20, 2004
  3. Fei Liu
    Replies:
    2
    Views:
    2,866
    Larry I Smith
    Apr 10, 2006
  4. sinbad

    extern int *a , int a[10]

    sinbad, Aug 10, 2007, in forum: C Programming
    Replies:
    6
    Views:
    520
    Keith Thompson
    Aug 10, 2007
  5. Doug
    Replies:
    1
    Views:
    515
    Gabriel Genellina
    Jun 29, 2009
Loading...

Share This Page