News for hackers. Stuff that matters.
Re:Proposal to add constexpr to C [pdf] by enriquto on Saturday October 16, 2021 @04:33PM (#28891232)
RAII is mostly already there, or at least a C-spirited version of it, thanks to variable length arrays. Unfortunately, there's little compiler support for large vla, both clang and gcc seem to choke on them because they put them on the stack (which is the naive implementation of vla).
Re:Proposal to add constexpr to C [pdf] by bonzini on Saturday October 16, 2021 @05:00PM (#28891465)
How would variable length arrays, for example, help with releasing a mutex on early returns from a function?
Re:Proposal to add constexpr to C [pdf] by enriquto on Saturday October 16, 2021 @05:30PM (#28891742)
They wouldn't, of course! Releasing resources silently (other than the memory of automatic variables) is very un-C-like.
Re:Proposal to add constexpr to C [pdf] by bonzini on Sunday October 17, 2021 @03:33AM (#28894652)
It's not silent, you do declare that you want it released; you just do it before and it applies to all early returns. For example

    MUTEX_LOCK_GUARD(&lock)
        for (i = 0; i < n; i++)
            if (a[i] == x)
                return i;
    return -1;
Real world example here: https://github.com/qemu/qemu/blob/master/block/iscsi.c#L325

And the implementation: https://github.com/qemu/qemu/blob/master/include/qemu/lockab... (after inlining, the abstraction is completely zero cost).

Re:Proposal to add constexpr to C [pdf] by dataflow on Saturday October 16, 2021 @05:57PM (#28891955)
> RAII is mostly already there

>> Releasing resources silently (other than the memory of automatic variables) is very un-C-like

The "R" is literally "resource", right? Sounds like instead of RAII you just meant unique_ptr.

Though I beg to differ on whether releasing memory automatically is any different from releasing other resources as far as being C-like is concerned!

Re:Proposal to add constexpr to C [pdf] by pjmlp on Sunday October 17, 2021 @02:38AM (#28894464)
VLA are out of the races since C11.

So you can forget about compilers caring to improve the quality of an optional feature, that was even cleaned from Linux kernel.

Re:Proposal to add constexpr to C [pdf] by enriquto on Sunday October 17, 2021 @05:24AM (#28895089)
I'll give you my VLA and my complex.h when you pry it from my cold, dead hands.
Re:Proposal to add constexpr to C [pdf] by pjmlp on Sunday October 17, 2021 @05:50AM (#28895205)
You are always free to keep your own fork of GCC.