2025-02-02 21:44:30 +05:00
2025-02-02 21:44:30 +05:00
2025-02-02 21:44:30 +05:00

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

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

#include <with99.h>

#define WITH99_RESOURCE_TYPE_intptr(...) int*
#define WITH99_RESOURCE_INIT_intptr(res, ...) (printf("Allocated to %p\n", res), *res = malloc(sizeof(int)), 0)
#define WITH99_RESOURCE_FREE_intptr(res, ...) (printf("Freed %p at %p\n", res, *res), free(*res))
#define WITH99_RESOURCE_THROWS_intptr(res, ...) 0

#define With WITH99_With

int main(void) {
	With(
		(intptr, a),
		(intptr, b)
	) {
		*a = 1;
		*b = 2;
		*a += *b;
		printf("%d\n", *a);
	}
}
Description
No description provided
Readme 0BSD 38 KiB
Languages
C 100%