Vicente Hernando Ara <[EMAIL PROTECTED]> 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. /Niels _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd