Update README.
This commit is contained in:
parent
bb481603a8
commit
3b4e555649
25
README.md
25
README.md
@ -6,20 +6,23 @@
|
|||||||
|
|
||||||
#include <with99.h>
|
#include <with99.h>
|
||||||
|
|
||||||
#define WITH99_resource_type_intptr_IMPL(...) v(int*)
|
#define WITH99_resource_intptr_IMPL(var, init) \
|
||||||
#define WITH99_resource_init_intptr_IMPL(var, init, ...) v((printf("Allocated to %p\n", var), var = malloc(sizeof(int)), *var = init, 0))
|
ML99_tuple(\
|
||||||
#define WITH99_resource_free_intptr_IMPL(var, ...) v((printf("Freed %p at %p\n", var, var), free(var)))
|
ML99_just(v(int *var)),\
|
||||||
#define WITH99_resource_throws_intptr_IMPL(...) ML99_false()
|
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 With WITH99_With
|
||||||
|
#define Never while(0)
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
With(
|
With(
|
||||||
(intptr, a, 1),
|
(intptr, a, 1),
|
||||||
(intptr, b, 3)
|
(intptr, b, 3)
|
||||||
) {
|
) do { // All resources are allocated here.
|
||||||
*a += *b;
|
*a += *b;
|
||||||
printf("%d\n", *a);
|
printf("%d\n", *a);
|
||||||
}
|
} Never; // And deallocated here.
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user