- Nov 6, 2004
- 324
- 0
- 0
Hi, I'm trying to complete a project for school involving the use of semaphores. I have included the proper header files (<semaphore.h> plus one for pthreads). I have pointed the compiler to the proper libraries as well. This is written in C. Yes, this is an assignment, but please be aware I am not looking for help with implementation, rather I can't seem to figure out this damnable compile error.
Here are lines 47 through 50 of my code, which are "simple" declarations of the semaphores and initializing them:
47 sem_t empty;
48sem_init(0, 0, 5);
49
50 sem_t full;
51 sem_init(&full, 0, 0);
Here are the messages I'm getting when I try and compile for line 48. I get the same set for line 50 but didn't post it for the sake of brevity:
|48|error: expected declaration specifiers or ?...? before ?&? token|
|48|error: expected declaration specifiers or ?...? before numeric constant|
|48|error: expected declaration specifiers or ?...? before numeric constant|
|48|warning: data definition has no type or storage class|
|48|warning: type defaults to ?int? in declaration of ?sem_init?|
I have declared all these outside the main() function. How can I resolve these errors? I'm baffled because it seems to indicate no data type for sem_t, but it is defined in semaphore.h, which I have included.
Thanks in advance for the help.
Here are lines 47 through 50 of my code, which are "simple" declarations of the semaphores and initializing them:
47 sem_t empty;
48sem_init(0, 0, 5);
49
50 sem_t full;
51 sem_init(&full, 0, 0);
Here are the messages I'm getting when I try and compile for line 48. I get the same set for line 50 but didn't post it for the sake of brevity:
|48|error: expected declaration specifiers or ?...? before ?&? token|
|48|error: expected declaration specifiers or ?...? before numeric constant|
|48|error: expected declaration specifiers or ?...? before numeric constant|
|48|warning: data definition has no type or storage class|
|48|warning: type defaults to ?int? in declaration of ?sem_init?|
I have declared all these outside the main() function. How can I resolve these errors? I'm baffled because it seems to indicate no data type for sem_t, but it is defined in semaphore.h, which I have included.
Thanks in advance for the help.
