1

I have 2 structures:

struct page
{
    VA adress;
    void* data;
    size_t filled_bytes;
};

struct mmemory
{
    int pages_count;
    int page_size;
    int pages_allocated;
    int pages_filled;
    struct page* table;
} *MMEM;

Then I've made mallocs:

MMEM = malloc(sizeof(struct mmemory));
MMEM->table = malloc(sizeof(struct page*) * n);

//in for loop
struct page* new_page = malloc(sizeof(struct page));
new_page->data = malloc(MMEM->page_size);
MMEM->table[MMEM->pages_allocated++] = *new_page;

I want to get the pointer to certain element of MMEM->table[0].data by index 0, for example. According to this question I should cast data to char* and than get it element by index. I've tryed:

&MMEM->table[MMEM->pages_filled].data[0] -- Expression must be a pointer to a complete object type using simple pointer arithmetic

&(char*)(MMEM->table[MMEM->pages_filled].data[0]) -- the same

Pavel Antspovich
  • 1,111
  • 1
  • 11
  • 27

0 Answers0