如何追查"syntax error: missing ')' before identifier"等原因?
How to track down the cause of "syntax error: missing ')' before identifier" and others?
我正在用visual studio用C编写一个项目,其中包含以下文件:
- multiThreadServer.cpp
- myLib.cpp
- myLib.h
第一个(multiThreadServer.cpp)包括这些
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
#include "myLib.h"
second (myLib.cpp) these
#include <WinSock2.h>
#include <stdio.h>
#include "myLib.h"
第3页(myLib.h)不包含任何内容
在。h文件中我定义了这些函数:
// Starts up the server.
INT start_server(const unsigned short port);
// Accept Connections.
BOOL accept_connections();
// Accept Client.
BOOL AcceptClient(PCLIENT current_client);
// Receiver Function for the thread.
DWORD WINAPI Receiver(LPVOID lpParam);
// Receive data from client.
BOOL recv_data(PCLIENT current_client, char *buffer, int size);
// End server.
VOID end_server();
// Send data.
BOOL send_data(PCLIENT current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(PCLIENT current_client);
// Send Data to all clients.
BOOL send_data_to_all(char *message);
这是myLib.cpp的一部分:
typedef struct _client{
SOCKADDR_IN address; // internal data structure regarding this client
SOCKET socket; // this clients socket
BOOL connected; // is this client connected
char IP[20]; // this clients IP address
int address_length; // internal data structure regarding this client
} CLIENT, *PCLIENT;
现在,当我要编译整个项目时,这些恼人的语法错误返回:
1> myLib.cpp
mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(8): error C2061: syntax error : identifier 'current_client'
mylib.h(8): error C2059: syntax error : ';'
mylib.h(8): error C2059: syntax error : ')'
mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(14): error C2061: syntax error : identifier 'current_client'
mylib.h(14): error C2059: syntax error : ';'
mylib.h(14): error C2059: syntax error : ','
mylib.h(14): error C2059: syntax error : ')'
mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(20): error C2061: syntax error : identifier 'current_client'
mylib.h(20): error C2059: syntax error : ';'
mylib.h(20): error C2059: syntax error : ','
mylib.h(20): error C2059: syntax error : ')'
mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(23): error C2061: syntax error : identifier 'current_client'
mylib.h(23): error C2059: syntax error : ';'
mylib.h(23): error C2059: syntax error : ')'
mylib.cpp(103): warning C4013: 'AcceptClient' undefined; assuming extern returning int
mylib.cpp(168): warning C4013: 'recv_data' undefined; assuming extern returning int
mylib.cpp(188): warning C4013: 'send_data' undefined; assuming extern returning int
mylib.cpp(189): warning C4013: 'disconnect_client' undefined; assuming extern returning int
mylib.cpp(270): error C2371: 'disconnect_client' : redefinition; different basic types
1> multiThreadServer.cpp
mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
1mylib.h(8): error C2061: syntax error : identifier 'current_client'
mylib.h(8): error C2059: syntax error : ';'
mylib.h(8): error C2059: syntax error : ')'
mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(14): error C2061: syntax error : identifier 'current_client'
mylib.h(14): error C2059: syntax error : ';'
mylib.h(14): error C2059: syntax error : ','
mylib.h(14): error C2059: syntax error : ')'
mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(20): error C2061: syntax error : identifier 'current_client'
mylib.h(20): error C2059: syntax error : ';'
mylib.h(20): error C2059: syntax error : ','
mylib.h(20): error C2059: syntax error : ')'
mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
mylib.h(23): error C2061: syntax error : identifier 'current_client'
mylib.h(23): error C2059: syntax error : ';'
mylib.h(23): error C2059: syntax error : ')'
我现在在网上搜索1.30小时,但我找不到解决它的方法。
与这里建议的不同,您可以在头文件中修复问题,而无需实际将PCLIENT
的定义移动到头文件中:
...
struct _client;
...
// Accept Client.
BOOL AcceptClient(struct _client* current_client);
...
// Receive data from client.
BOOL recv_data(struct _client* current_client, char *buffer, int size);
...
// Send data.
BOOL send_data(struct _client* current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(struct _client* current_client);
...
相关文章:
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- Arduino无法编译名为SP:"Expected ')' before '(' token"的变量
- 为什么我的功能在使用 goto 时会给我带来"expected primary-expression before '}' token"?
- 消除"Undeclared identifier"错误
- 为什么即使在定义之后仍存在"Identifier is undefined error "?
- 我正在尝试创建一个枚举,但得到了"identifier expected error"
- 如何修复此错误"expected primary expression before 'int'"?
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- 使用结构和数组时的"expected primary expression before '.' token"
- 为什么我在" 'X' identifier not found' "上收到错误
- 为什么在使用 auto_ptr 样式类访问结构成员时会出现'unidentified identifier'?
- 如何解决"Expected expression before " = " token"?
- 如何解决"if"块中的"Undeclared identifier error"?
- 类型字符串::长度()。我得到了"Unable to resolve identifier length"
- 使用类型类的向量时获取'undeclared identifier'
- 错误:创建模板类时"expected unqualified-id before '{' token"
- AWS Lambda C++ 开发工具包"Process exited before completing request"
- C++:将运算符作为参数传递会导致错误"expected an identifier"
- 使用结构体在课堂上"Expected an identifier"和"missing ';' before '.'"
- 如何追查"syntax error: missing ')' before identifier"等原因?