C compiling error: expected expression before ‘{’ token
Hi. I have a compiling error which doesn't seem to want to go away. I suppose I could try to do it another way, but it seems really annoying that it is not working and I'm not sure why.
The code is compiled with gcc. I'm just compiling the object code now - not yet linking it into the program. Here is the compiler error: Code:
bash-3.00$ gcc -c menu_browser.c Code:
#include <stdlib.h> Here is menu_browser.h: Code:
#ifndef _MENU_BROWSER_ MenuItem_List_Bundle. "disp_thread_modes.h" simply provides a few constants. |
Solved... I think
I think I figured out what was wrong. The problem is that PTHREAD_MUTEX_INITIALIZER is, well, an initializer... and I was trying to use it differently.
Here is the definition from pthread.h: Code:
# define PTHREAD_MUTEX_INITIALIZER \ Code:
struct Menu_Browser_Ctrl * create_menu_browser_ctrl(MenuItem_List_Bundle * menuitem_list_bundle) |
As you probably already realize, this has nothing to do with whether it's in a struct.
It has everything to do with the difference between initializing a variable as you declare it and assigning to it after it's been declared. To see the difference in action, run this shell script: Code:
cat > 1.c <<EOD; cat -n 1.c; gcc -Wall -pthread 1.c -o 1 Code:
1 #include <stdlib.h> If you wish to initialize a mutex at a point other than when you declare it, a good way is to use pthread_mutex_init(). Hope this helps. |
Quote:
|
All times are GMT -5. The time now is 04:20 PM. |