Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

windows - In C assigning value to a field inside structure is resulting in "expected a ';'" error

I have assigned values to a fields in a structure. This resulted in multiple errors.

typedef struct t_queue {
int head = 0;
int tail = 0;
int maxSize = 0;
int size = 0;
SOCKET* queue = NULL;
}Queue;

typedef struct t_threadData {
int topicID;

bool isEngineActive = FALSE;
bool isServerActive = TRUE;
int numberOfConnectedSubs = 0;

Queue* queue;

HANDLE PublisherReady;
HANDLE ThreadReady;
HANDLE BarrierOK;
CRITICAL_SECTION Critical_Section;

int NumberOfThreadsWaiting = 0;
SOCKET sockets[NUMBER_OF_SUBSCRIBERS];

}ThreadData;

Errors are:

  1. E0065 expected a ';'

  2. E0020 identifier "bool" is undefined

I'm working in C on Windows 10 using Visual Studio Enterprise 2017.

Thank you for your help in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Read Modern C and see this C reference. If you compile with a recent GCC compiler, use gcc -Wall -Wextra -g to compile your code. Read also the documentation of your C compiler, and enable all warnings in it. Read also the documentation of your debugger (e.g. GDB)

You should code:

typedef struct t_queue {
  int head;
  int tail;
  int maxSize;
  int size;
  SOCKET* queue;
}  Queue;

BTW, your field names are confusing. Since head and tail suggests a doubly-linked list. Then they should be pointers!

Consider also using the Clang static analyzer -or Frama-C- on your project.

Take inspiration from the source code of some existing open source software coded in C (like Glib, GNU make, the Linux kernel, GNU guile, etc...)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...