ok this is part1 to have the program shorter
Iam doing this program in C, and now i have broken it up into a smaller program.
Code:
#include<stdio.h>
int main()
{
void producer ( void )
{
do
produce ( item );
wait ( empty ); // empty is semaphore
wait ( mutex ); // mutex is semaphore
put ( item );
signal ( mutex );
signal ( full );
while ( 1 );
}
class event_counter
{
int ec; // Event counter
public:
event_counter ( void ) // Default constructor
{
ec = 0;
}
int read ( void ) const { return ( ec ); }
void advance ( void ) { ec++; }
void await ( const int v ) { while ( ec < v ); }
};
extern event_counter in, out; // Shared event counters
void producer ( void )
{
int sequence ( 0 );
do
produce ( item );
sequence++;
out.await ( sequence - num_buffers );
put ( item );
in.advance();
while ( 1 );
}
}
this are my errors, what is wrong and how can i fix it?
Code:
consumer.c:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘wait’
consumer.c: In function ‘producer’:
consumer.c:10: error: ‘item’ undeclared (first use in this function)
consumer.c:10: error: (Each undeclared identifier is reported only once
consumer.c:10: error: for each function it appears in.)
consumer.c:11: error: expected ‘while’ before ‘wait’
consumer.c:12: error: ‘mutex’ undeclared (first use in this function)
consumer.c:15: error: ‘full’ undeclared (first use in this function)
consumer.c: In function ‘consumer’:
consumer.c:21: error: ‘full’ undeclared (first use in this function)
consumer.c:22: error: expected ‘while’ before ‘wait’
consumer.c:23: error: ‘item’ undeclared (first use in this function)
consumer.c:24: error: ‘mutex’ undeclared (first use in this function)
consumer.c:25: error: ‘empty’ undeclared (first use in this function)
consumer.c: In function ‘main’:
consumer.c:30: error: ‘class’ undeclared (first use in this function)
consumer.c:30: error: expected ‘;’ before ‘event_counter’
consumer.c:43: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘in’
consumer.c:43: error: ‘in’ undeclared (first use in this function)
consumer.c:43: error: ‘out’ undeclared (first use in this function)
consumer.c:56: error: redefinition of ‘consumer’
consumer.c:19: error: previous definition of ‘consumer’ was here
consumer.c: In function ‘consumer’:
consumer.c:57: error: expected declaration specifiers or ‘...’ before numeric constant
consumer.c:59: error: invalid lvalue in increment
consumer.c:60: error: expected ‘while’ before ‘in’
consumer.c:61: error: ‘item’ undeclared (first use in this function)
consumer.c:66:2: warning: no newline at end of file