[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cthreads to Pthreads code.

From: Niels Möller
Subject: Re: Cthreads to Pthreads code.
Date: 24 Oct 2002 09:21:54 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Vicente Hernando Ara <address@hidden> writes:

>  * This last is an error I get in exec.c file.
> static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
> This trigger an error when compiling:
>    exec.c:1382: initializer element is not constant
> however:
>     pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
> compiles ok. Why is that?

Appearantly, PTHREAD_MUTEX_INITIALIZER is not a constant expression.
Perhaps that's a bug, I'd expect the pthreads spec to require that
it's constant, but I haven't read that.

Initializers for statically allocated variables must be constant, they
are typically put into the datasegment of the executable, and there's
no code that initializes them at run-time (unlike C++ constructors
which would run just before main is called).

On the other hand, it's perfectly fine to have non-constant
initializers for "automatic", stack allocated, variables. The compiler
will generate code to initialize them properly at run-time. At least
that's the case for GNUC, in ANSI-C (c89) you can't do that with
initializers for structs and arrays, they must always be constant
expressions. Not sure if the latest C standard, c99, has fixed that.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]