[LC++]Why doesn't PTHREAD_MUTEX_INITIALIZER work my constructor?

Greg Wiley greg at orthogony.com
Sun Nov 17 04:58:01 UTC 2002


filiond at videotron.ca wrote:

> mutex = PTHREAD_MUTEX_INITIALIZER;
> in the class contructor I get a compilation error. If I use:
> pthread_mutex_init (&mutex, NULL);
> it works.
> [...]
> Threads::Threads ()
> {
> // This return a compilation error of:
> // Threads.cc: In method `Threads::Threads()':
> // Threads.cc:6: parse error before `{'
> //
> //mutex = PTHREAD_MUTEX_INITIALIZER;

Your guess is correct, the PTHREAD_MUTEX_INITIALIZER
macro must be evaluated and the assignment made in a
compile-time context.  Try replacing the text for
PTHREAD_MUTEX_INITIALIZER directly in your code and
you might see what the compiler dislikes.

  -=greg






More information about the tuxCPProgramming mailing list