#ifndef STACK_H
#define STACK_H
#include <assert.h>
#include <stdlib.h>
#define stack_of(T) struct { size_t top; T value[]; }
 
#define operate(list, ...) {                                         \
    size_t x = list ? list->top : 0                                  \
         , y = x + 1;                                                \
    if ((x & y) == 0) {                                              \
        void *temp = realloc(list, sizeof *list                      \
                                 + (x + y) * sizeof list->value[0]); \
        if (!temp)                                                   \
            return EXIT_FAILURE;                                     \
        list = temp;                                                 \
    }                                                                \
    __VA_ARGS__;                                                     \
}
 
#define push(list, v) operate(list, list->value[x] = v; list->top = y)
#define pop(list) (assert(list && list->top), list->value[--list->top]); \
                  operate(list, )
#endif

// #include "stack.h" // embedded above
#include <stdio.h>
int main(void) {
    stack_of(int) *fubar = NULL;
    int x;
    push(fubar, 42);
    push(fubar, -1);
    x = pop(fubar); printf("popped: %d\n", x);
    x = pop(fubar); printf("popped: %d\n", x);
    x = pop(fubar); printf("popped: %d\n", x);
    free(fubar);
}