0

I cannot spot any missing bracket. What's the problem?

#ifndef PROCINFO_H_
#define PROCINFO_H_
#include <linux/limits.h>
#include <elf.h>

 enum boolean {f,t};

typedef struct {

    enum boolean fileHdr = 0;
    enum boolean programHdr=0;
    enum boolean sectionHdr = 0;
    enum boolean info = 0;
    enum boolean def = 0;
} procInfo;

typedef struct {
    char filename[NAME_MAX]; 
    procInfo info;
} procFile;


#endif /* PROCINFO_H_ */

Errors:

expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token  
make: *** [src/subdir.mk:20: src/elfViewer.o] Error 1  
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • 3
    Welcome to SO. You don't have a missing bracket. You have `=` inside a struct definition. That is not possible in C. You can only assign values in variable definitions. There is no such thing as a default value for types in C. – Gerhardh Dec 15 '21 at 17:23
  • 2
    For future questions please post the complete error message. It should include the exact location where the error is detected. – Gerhardh Dec 15 '21 at 17:24
  • Does this answer your question? [default value for struct member in C](https://stackoverflow.com/questions/13716913/default-value-for-struct-member-in-c) – Gerhardh Dec 15 '21 at 17:27

1 Answers1

1

You may not initialize data members of a structure in C moreover in a typedef declaration as you are doing

typedef struct {

    enum boolean fileHdr = 0;
    enum boolean programHdr=0;
    enum boolean sectionHdr = 0;
    enum boolean info = 0;
    enum boolean def = 0;
} procInfo;

You need to write

typedef struct {

    enum boolean fileHdr;
    enum boolean programHdr;
    enum boolean sectionHdr;
    enum boolean info;
    enum boolean def;
} procInfo;

When an object of this type will be defined you may provide an initialization for it as for example

pricinfo info = { 0 };
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335