Home > Blockchain >  Error: "expected ‘:’, ‘,’, ‘;’, ‘}’ " and "struct has no member named"
Error: "expected ‘:’, ‘,’, ‘;’, ‘}’ " and "struct has no member named"

Time:12-16

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  

CodePudding user response:

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 };
  • Related