2025-04-10 00:58:05 +05:00
2025-04-09 23:44:55 +05:00
2025-02-02 21:47:10 +05:00
2025-04-10 00:58:05 +05:00

Metalang99-based library, adding Python-like "with" blocks

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

#include <with99.h>

#define WITH99_resource_intptr_IMPL(var, init) \
        ML99_tuple(\
                ML99_just(v(int *var)),\
                ML99_just(v((var = malloc(sizeof(int)),printf("Allocated %p(%s)\n", var, #var), *var = init, 0))),\
                ML99_just(v((printf("Freed %p(%s)\n", var, #var), free(var))))\
        )

#define With WITH99_With
#define Never while(0)

int main(void) {
        With(
                (intptr, a, 1),
                (intptr, b, 3)
        ) do { // All resources are allocated here.
                *a += *b;
                printf("%d\n", *a);
        } Never; // And deallocated here.
}
Description
No description provided
Readme 0BSD 38 KiB
Languages
C 100%