#include <stdio.h>
#include <malloc.h>

typedef struct
{
    int width;
    int height;
    int *buffer;
} grid;

grid grid_new(int grid_width, int grid_height)
{
    grid p_grid;
    p_grid.buffer = NULL;
    if ((grid_width % 2 != 0) || (grid_height % 4 != 0))
        return p_grid;

    int group_height = 4;
    int group_width = 2;

    p_grid.buffer = calloc(grid_width / group_width * grid_height / group_height, sizeof(int));
    p_grid.width = grid_width;
    p_grid.height = grid_height;
    return p_grid;
}

void grid_free(grid *p_grid)
{
    free(p_grid->buffer);
    free(p_grid);
}

void grid_clear(grid *g)
{
    // ToDo: Iterate over all elements in the buffer
    int elements = sizeof(g->buffer) / sizeof(int);
    printf("Elements: %i", elements);
}

int main() 
{
	grid p = grid_new(16, 16);
	printf("%d %d", p.width, p.height);
}
