News for hackers. Stuff that matters.
Re:Modern C for C++ Peeps by WalterBright on Saturday January 07, 2023 @02:07PM (#34291441)
C:

    char *buf __attribute__ ((__cleanup__(free_buf))) = malloc(1024);
D:

    char* buf = cast(char*)malloc(1024);
    scope (exit) free(buf);
https://dlang.org/spec/statement.html#scope-guard-statement

The rationale for it:

https://dlang.org/articles/exception-safe.html

The idea for this came from Andrei Alexandrescu and Petru Marginean who proposed it for C++:

http://drdobbs.com/184403758

There are no comments on this comment yet.