当前位置: 技术问答>linux和unix
gcc编译错误,求助!
来源: 互联网 发布时间:2016-08-09
本文导语: 源代码如下: 1 #include "unpthread.h" 2 3 #define MAXFILES 20 4 #define SERV "80" /* port number or server name */ 5 6 struct file { 7 char *f_name; /* filename */ 8 char *f_host; /* hostn...
源代码如下:
1 #include "unpthread.h"
2
3 #define MAXFILES 20
4 #define SERV "80" /* port number or server name */
5
6 struct file {
7 char *f_name; /* filename */
8 char *f_host; /* hostname or IPv4/IPv6 address */
9 int f_fd; /* description */
10 int f_flags; /* F_xxx below */
11 pthread_t f_tid; /* thread ID */
12 } file[ MAXFILES ];
13
14 #define F_CONNECTING 1; /* connect( ) in progress */
15 #define F_READING 2; /* connect( ) complete; now reading */
16 #define F_DONE 4; /* all done */
17 #define F_JOINED 8; /* main has pthread_join'ed */
18
19 #define GET_CMD "GET %s HTTP/1.0rnrn"
20
21 int ndone; /* number of terminated threads */
22 pthread_mutex_t ndone_mutex = PTHREAD_MUTEX_INITIALIZER;
23 pthread_cond_t ndone_cond = PTHREAD_COND_INITIALIZER;
24
25 /* globals */
26 int nconn, nfiles, nlefttoconn, nlefttoread;
27
28 /* function prototypes */
29 void home_page( const char *, const char * );
30 void *do_get_read( void * );
31 void write_get_cmd( struct file * );
32
33 int
34 main( int argc, char **argv )
35 {
36 int i, n, maxconn;
37 pthread_t tid;
38 struct file *fptr;
39
40 if ( argc f_name );
88 }
89 }
90 Pthread_mutex_unlock( &ndone_mutex );
91 }
92
93 exit( 0 );
94 }
95
96 void *
97 do_get_read( void *vptr )
98{
99 int fd, n;
100 char line[ MAXLINE ];
101 struct file *fptr;
102
103 fptr = ( struct file * ) vptr;
104
105 fd = Tcp_connect( fptr->f_host, SERV );
106 fptr->f_fd = fd;
107 printf( "do_get_read for %s, fd %d, thread %dn",
108 fptr->f_name, fd, fptr->f_tid);
109 write_get_cmd( fptr ); /* write( ) the GET command*/
110 /* Read server's reply */
111 for ( ; ; ) {
112 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
113 break; /* server closed connection */
114 printf( "read %d bytes from %sn", n, fptr->f_name );
115 }
116 printf( "end-fo-file on %sn", fptr->f_name );
117 Close( fd );
118 Pthread_mutex_lock( &ndone_mutex );
119 fptr->f_flags = F_DONE; /* close F_READING */
120
121 ndone++;
122 Pthread_cond_signal( &ndone_cond );
123 Pthread_mutex_unlock( &ndone_mutex );
124
125 return( fptr ); /* terminate thread */
126 }
127
128 void
129 write_get_cmd( struct file *fptr )
130 {
131 int n;
132 char line[ MAXLINE ];
133
134 n = snprintf( line, sizeof( line ), GET_CMD, fptr->f_name );
135 Writen( fptr->f_fd, line, n );
136 printf( "worte %d bytes for %sn", n, fptr->f_name );
137
138 fptr->f_flags = F_READING; /* clear F_CONNECTING */
139 }
140
141 void
142 home_page( const char *host, const char *fname )
143 {
144 int fd, n;
145 char line[ MAXLINE ];
146
147 fd = Tcp_connect( host, SERV ); /* blcoking connect( ) */
148
149 n = snprintf( line, sizeof( line ), GET_CMD, fname );
150 Writen( fd, line, n );
151
152 for ( ; ; ) {
153 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
154 break; /* server closed connection */
155 printf( "read %d bytes of home pagen", n );
156 /* do whatever with data */
157 }
158 printf( "end-of-file on home pagen" );
159 Close( fd );
160 }
[web.c]
是UNP中的一个例子,编译命令是:
gcc -o web web.c -lunp -lpthread
web.c: 78: error: expected ')' before ';' token
大家帮忙检查一下那里错了 ?
1 #include "unpthread.h"
2
3 #define MAXFILES 20
4 #define SERV "80" /* port number or server name */
5
6 struct file {
7 char *f_name; /* filename */
8 char *f_host; /* hostname or IPv4/IPv6 address */
9 int f_fd; /* description */
10 int f_flags; /* F_xxx below */
11 pthread_t f_tid; /* thread ID */
12 } file[ MAXFILES ];
13
14 #define F_CONNECTING 1; /* connect( ) in progress */
15 #define F_READING 2; /* connect( ) complete; now reading */
16 #define F_DONE 4; /* all done */
17 #define F_JOINED 8; /* main has pthread_join'ed */
18
19 #define GET_CMD "GET %s HTTP/1.0rnrn"
20
21 int ndone; /* number of terminated threads */
22 pthread_mutex_t ndone_mutex = PTHREAD_MUTEX_INITIALIZER;
23 pthread_cond_t ndone_cond = PTHREAD_COND_INITIALIZER;
24
25 /* globals */
26 int nconn, nfiles, nlefttoconn, nlefttoread;
27
28 /* function prototypes */
29 void home_page( const char *, const char * );
30 void *do_get_read( void * );
31 void write_get_cmd( struct file * );
32
33 int
34 main( int argc, char **argv )
35 {
36 int i, n, maxconn;
37 pthread_t tid;
38 struct file *fptr;
39
40 if ( argc f_name );
88 }
89 }
90 Pthread_mutex_unlock( &ndone_mutex );
91 }
92
93 exit( 0 );
94 }
95
96 void *
97 do_get_read( void *vptr )
98{
99 int fd, n;
100 char line[ MAXLINE ];
101 struct file *fptr;
102
103 fptr = ( struct file * ) vptr;
104
105 fd = Tcp_connect( fptr->f_host, SERV );
106 fptr->f_fd = fd;
107 printf( "do_get_read for %s, fd %d, thread %dn",
108 fptr->f_name, fd, fptr->f_tid);
109 write_get_cmd( fptr ); /* write( ) the GET command*/
110 /* Read server's reply */
111 for ( ; ; ) {
112 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
113 break; /* server closed connection */
114 printf( "read %d bytes from %sn", n, fptr->f_name );
115 }
116 printf( "end-fo-file on %sn", fptr->f_name );
117 Close( fd );
118 Pthread_mutex_lock( &ndone_mutex );
119 fptr->f_flags = F_DONE; /* close F_READING */
120
121 ndone++;
122 Pthread_cond_signal( &ndone_cond );
123 Pthread_mutex_unlock( &ndone_mutex );
124
125 return( fptr ); /* terminate thread */
126 }
127
128 void
129 write_get_cmd( struct file *fptr )
130 {
131 int n;
132 char line[ MAXLINE ];
133
134 n = snprintf( line, sizeof( line ), GET_CMD, fptr->f_name );
135 Writen( fptr->f_fd, line, n );
136 printf( "worte %d bytes for %sn", n, fptr->f_name );
137
138 fptr->f_flags = F_READING; /* clear F_CONNECTING */
139 }
140
141 void
142 home_page( const char *host, const char *fname )
143 {
144 int fd, n;
145 char line[ MAXLINE ];
146
147 fd = Tcp_connect( host, SERV ); /* blcoking connect( ) */
148
149 n = snprintf( line, sizeof( line ), GET_CMD, fname );
150 Writen( fd, line, n );
151
152 for ( ; ; ) {
153 if ( ( n = Read( fd, line, MAXLINE ) ) == 0 )
154 break; /* server closed connection */
155 printf( "read %d bytes of home pagen", n );
156 /* do whatever with data */
157 }
158 printf( "end-of-file on home pagen" );
159 Close( fd );
160 }
[web.c]
是UNP中的一个例子,编译命令是:
gcc -o web web.c -lunp -lpthread
web.c: 78: error: expected ')' before ';' token
大家帮忙检查一下那里错了 ?
|
14~17行,宏定义1248后面的分号都去掉
F_DONE被替换成了4;
78行经过预处理之后就变成了 if ( file[ i ].f_flags & 4; ) {
F_DONE被替换成了4;
78行经过预处理之后就变成了 if ( file[ i ].f_flags & 4; ) {