C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] (SC22WG14.18841) [Fwd: sudo buffer overlow]

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Sat, 30 Jan 2021 17:47:08 +0000
Am Samstag, den 30.01.2021, 15:00 +0000 schrieb Niall Douglas via Liaison:
> On 28/01/2021 21:48, Uecker, Martin via Liaison wrote:
>
> > In C we discussed something like:
> >
> > struct foo {
> >    int n;
> >    float (*ap)[.n];
> > };
> >
> > An alternative could a wide pointer type:
> >
> > struct foo {
> > float (*ap)[:];
> > };
> >
> > If one does not want to introduce a general wide pointer
> > type, one could allow this only inside aggregates.
> > The bound would be stored in a hidden variable
> > and set automatically when the pointer is assigned.
> >
> > This should be relatively simple to specify.
>
> Speaking personally, I have always felt C could sorely do with a
> language built-in equivalent to span<T>/string_view from C++ as a 
> lightweight range. Even if built-in native objects for arrays or strings
> is too much to ask for now, just spans/views (borrowed refs in Rust
> parlance) would be an enormous value add.
>
> The most obvious formulation of implementation is a wide pointer type,
> as you suggest. So, you'd have some bits for indicating which kind of
> wide pointer type it is, the pointer itself, and either one or two
> offsets from that pointer. The zero, one or two offsets may immediately
> follow the pointer value, or live just before the pointed at storage.
>
> On top of such a fundamental construct, you can build fixed capacity
> array storage but with dynamically resized contents i.e. a deterministic
> std::vector. You can build strings, arrays, with or without runtime
> enforced checking. You can pass around subslices of all those, safely.
> The opportunities enabled here are huge.
>
> I think the chances of C++ adopting VLAs are indistinguishable from
> zero. But C supporting a subset of C++ ranges (specifically, contiguous
> ranges), well that I can see plenty of WG21 support for, in principle at
> least.

Hi Niall,

the only type I am missing in C is a wide function type similar
to std::function to call callable objects from other languages.
(In theory, function pointers in C could be wide but ABIs can
not changed.)


The wide pointers for arrays would be syntactic sugar
around variably-modified type, so nothing we need urgently.

I am not sure what C++ does here we could adapt, you mention
span or ranges. But what would be the corresponding
C++ type for the following dynamic multi-dimensional array?

double (*ten)[z][y[x] = malloc(sizeof *ten);

Best,
Martin

Received on 2021-01-30 11:47:20