C++ Logo

liaison

Advanced search

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

From: Jens Gustedt <jens.gustedt_at_[hidden]>
Date: Mon, 1 Feb 2021 11:20:16 +0100
Martin,

on Sun, 31 Jan 2021 20:29:35 +0000 you ("Uecker, Martin"
<Martin.Uecker_at_[hidden]>) wrote:

> Am Sonntag, den 31.01.2021, 20:46 +0100 schrieb Jens Gustedt via
> Liaison:
> > VLA (or VM types for that matter) only have the size (or sizes if
> > multidimensional) as dynamic components and are not very difficult,
> > neither to implement nor to use. C has them since a long time and
> > they work well. And, contrary to the common belief and urban
> > legends, they can be used to make programming with large arrays or
> > even matrices much safer.
> >
> > I would hope that we could go here in a similar way to what I am
> > trying to do with lambdas for WG14: take the simple and
> > existing things that are well accomplished and mastered in one
> > language and pull them into the other language to broaden the
> > intersection. VM types here would be important to have for function
> > interface compatibility between C and C++.
>
> I agree,
>
> I think a good first step would be simple ignoring the
> length in the first level for extern C.
>
> extern "C" void foo(int N, double x[N]);
>
> becomes
>
> extern "C" void foo(int N, double x[/* N */]);
>
> for the C++ side. This would already remove most
> of the pain for shared headers.

I would say "some", but not "most". If the expression of the first
dimension is ignored, because that is rewritten to a pointer, anyhow,
that would be a good start for code using vectors, yes. Finally, this
would not be much different than what many C compilers did for
years. But it would also miss the possibility of bounds propagation.

(There are also some other minor incompatibilities for qualifiers and
`static` that in C may also appear between the `[]`)

Unfortunately, for code using higher dimensional arrays this is not a
solution, because `double x[][]` would be no sensible definition of a
parameter. The sizes of the second and further dimensions are needed,
even if they are constants.

Jens

-- 
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::

Received on 2021-02-01 04:20:22