Page 1 of 1
Gah. (C issues)
Posted: 2010.02.18 (22:33)
by scythe
Code: Select all
pool->mutex = { { 0, 0, 0, 0, 0, { 0 } } };
The preceding line gives the error:
"expected expression before { token".
Now, what I'm guessing is that the compiler version I'm using doesn't like the way this code creates a pointer to an array. It's not my code, though, so how do I change this so it compiles but acts the same as the preceding? I'm thinking something like
Code: Select all
pool->mutex = & ( {0, 0, 0, 0, 0, { 0 } } );
, but I'm not entirely sure that will work.
Re: Gah. (C issues)
Posted: 2010.02.19 (03:58)
by taaveti
You can only set a struct that way on initialization, so while
Code: Select all
pthread_mutex_t mymutex = { { 0, 0, 0, 0, 0, { 0 } } };
is valid,
Code: Select all
pthread_mutex_t mymutex;
mymutex = { { 0, 0, 0, 0, 0, { 0 } } };
is not.
A way around this limitation would be to do something like this:
Code: Select all
pthread_mutex_t mymutex;
pthread_mutex_t tmpMutex = { { 0, 0, 0, 0, 0, { 0 } } };
mymutex = tmpMutex;
but if you are, in fact, using a pthread mutex then you really shouldn't get into the habit of assigning the value of one pthread_mutex_t to another (probably won't hurt with the initializer value, but others could lead to some unfortunate and hard-to-debug problems). In that case, it's probably better to use pthread_mutex_init:
Code: Select all
pthread_mutex_t mymutex;
pthread_mutex_init(&mymutex,NULL);
Re: Gah. (C issues)
Posted: 2010.02.19 (10:26)
by scythe
It works!
ilu