0
votes

I'm trying to compile a project and an error (the only error, at that) is being raised in the header file.

error: expected specifier-qualifier-list before ‘draw’

The offending line of code can be found here:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define LNAME 129 
#define DNUM 17 

typedef struct {
  char name[LNAME]; 
  double x[DNUM];        
  double y[DNUM];        
  double x_point[DNUM];  
  double y_point[DNUM];
  int draw;                 
  draw = 1;                         //<< the line GCC references in the error for reference
  memset(name, 0, sizeof(name));
  memset(x, 0, sizeof(x));
  memset(y, 0, sizeof(y));
} Figure;

I'm rather new to C so if anyone can give a little insight I'd appreciate it.

1
Not sure about the before part, but a struct isn't a function; you can't call functions from the struct definition. - chris
The compiler expects a declaration there, since that's all you can have in a struct definition. - Daniel Fischer
Oh, wow, I missed the draw = 1; line entirely, even with the comment, which I thought was on the int draw; line. Wow... - chris

1 Answers

0
votes

You can't give structure members an initial value. You have to write a constructor function to initialize all your members in a particular instance of a struct.