C++ Logo

std-proposals

Advanced search

Re: Arrays (VLAs) as function parameters (as in C99)

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 14 Nov 2021 11:06:15 -0800
On Friday, 12 November 2021 13:30:26 PST Alejandro Colomar (man-pages) via
Std-Proposals wrote:
> > #if __STDC_VERSION__ >= 199901L
> > # define size_at_least(n) static n
> > # define size_exactly(n) static restrict n
> > #else
> > # define size_at_least(n)
> > # define size_exactly(n)
> > #endif
> >
> > void process_array(size_t count, char payload[size_at_least(count)]);
>
> I didn't think of it that way, but yes, it makes sense.
> I only thought about making C syntax (without macros hiding the stuff)
> compile in C++.
>
> BTW, 'static restrict n' doesn't mean size_exactly() unless I'm also a
> bit blind here. But yes, that concept makes sense.

I think I got the syntax inverted. "static n" means "exactly n" and then they
added the "restrict" to indicate it's at least that many.

Shows you how little this gets used. And it's not just the fact that I'm a C++
developer primarily -- if I ask my colleagues who code mostly in C, I bet you
they won't know.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2021-11-14 13:06:20