1

Why this error is popping up (for int index = -1). Here's the segment of code:

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

#define Offset 12

int num_frames;

struct node
    {
        struct node* next;
        long data;
    };

struct page
{
    int index = -1;
    int frame = -1;
    int dirty = 0; //0 is clean, 1 is dirty
    int valid = 0; //0 is not, 1 is valid
    int referenced = 0; //0 is not, 1 is referenced
};

Any insight would be appreciated!

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
kyhart
  • 13
  • 3
  • 3
    you cannot initialize struct members in the declaration. That syntax (tho maybe useful) does not exist – pm100 Apr 04 '18 at 15:05

1 Answers1

3

The problem is in

struct page
{
    int index = -1;
    int frame = -1;
    int dirty = 0; //0 is clean, 1 is dirty
    int valid = 0; //0 is not, 1 is valid
    int referenced = 0; //0 is not, 1 is referenced
};

You define a new type struct page and try to initialize it at the same declaration. Types don't have default values. The right way to do it is to define the new type struct page without initial values, and then initiate a new struct page variable with those values.

galfisher
  • 1,122
  • 1
  • 13
  • 24