top | item 16662873

(no title)

BruceIV | 8 years ago

[On the Cforall team] For what it's worth, one of the features Cforall adds to C is RAII.

The exception implementation isn't done yet, but it's waiting on (limited) run-time type information, it already respects RAII.

discuss

order

RhysU|8 years ago

I have often wanted c99 with destructors for RAII purposes.

enriquto|8 years ago

you do not need destructors if you put your stuff on the stack

seabrookmx|8 years ago

I might have missed this.. but how is Cforall implemented?

A new GCC or LLVM frontend, or is it a transpiles-to-C implementation ala. Nim or Vala?

BruceIV|8 years ago

Transpiles-to-(GNU-)C -- it was first written before LLVM, if we were starting the project today it would likely be a Clang fork.

baybal2|8 years ago

What I will like is more strict compile time checks. Most C pros have to rely on external tooling for that.

BruceIV|8 years ago

It's maybe not quite what you're looking for, but Cforall's polymorphic functions can eliminate nearly-all the unsafety of void-pointer-based polymorphism at little-to-no extra runtime cost (in fact, microbenchmarks in our as-yet-unpublished paper show speedup over void-pointer-based C in most cases due to more efficient generic type layout). As an example:

    forall(dtype T | sized(T))
    T* malloc() {  // in our stdlib
        return (T*)malloc(sizeof(T)); // calls libc malloc
    }

    int* i = malloc(); // infers T from return type