tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.03k stars 48 forks source link

Add destructor for file-pointers #111

Closed porky11 closed 7 years ago

porky11 commented 7 years ago

(not tested) Why not implemented yet? Or is some module stdio.dt planned, which should be used instead?

tomhrr commented 7 years ago

On Sun, Sep 18, 2016 at 04:16:43PM -0700, Fabio Krapohl wrote:

Why not implemented yet?

The main reason is that the cstdio module should operate as similarly as possible to C's stdio library. Aside from that, adding this would mean that users could not call 'fclose' manually, but would instead have to scope the variable so as to have it close at the desired time. Also, passing pointer-to-file to another function would cause that value to be destroyed when the function finishes executing (at least without copy/move being implemented as well, but that can't be done sensibly in this case anyway).

Or is some module stdio.dt planned, which should be used instead?

Although no separate stdio module is currently planned, that would be the logical place to put a file wrapper that implemented init/move/copy/destroy so as to make it easier to use than a raw pointer-to-file.