Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A failure will not appear until a unit has passed final inspection.


devel / comp.lang.c / Re: "span"

SubjectAuthor
* "span"Stefan Ram
+* Re: "span"Thiago Adams
|`* Re: "span"Ben Bacarisse
| `* Re: "span"Thiago Adams
|  `* Re: "span"Keith Thompson
|   `* Re: "span"Ben Bacarisse
|    `* Re: "span"Keith Thompson
|     +- Re: "span"Ben Bacarisse
|     `- Re: "span"Lawrence D'Oliveiro
+* Re: "span"Ben Bacarisse
|`- Re: "span"Kaz Kylheku
+- Re: "span"fir
`- Re: "span"Blue-Maned_Hawk

1
"span"

<span-20240322122631@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34627&group=comp.lang.c#34627

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.c
Subject: "span"
Date: 22 Mar 2024 11:30:56 GMT
Organization: Stefan Ram
Lines: 27
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <span-20240322122631@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de GJsj7qnSwEYTNfaDR1QHAg0w6nC0iC49HqiACfMATgJFYp
Cancel-Lock: sha1:xXpEut2ZE64CxeCmEFbSy8M+xy0= sha256:3pG9ilK7VPJPHFSBgAQ9gMHcSYk7M6aepfySdcwCfJI=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Fri, 22 Mar 2024 11:30 UTC

Some people suggested to introduce a feature "span" (probably a
type) into C++, so that when one has an int array "a" and calls
"f( a )", the length of a is being transferred to "f", which "f"
is defined using "void f(span<int> a)". The "span" in "f" then
knows the length of "a". This is supposed to be less error prone
than passing a pointer with a separate length argument.

Of course, I immediately wondered whether one could implement
such a "span" for C, and here's a draft:

#include <stdio.h>

#define SPAN_PARAM(x,a,n) x*a,size_t const n
#define SPAN(a) a,(sizeof a/sizeof 0[a])

void print( SPAN_PARAM( int, a, n ))
{ for( size_t i = 0; i < n; ++i )
printf( "%lld: %d\n", i, a[ i ]); }

int main( void )
{ int a[ 3 ]={ 4, 6, 8 };
print( SPAN(a) ); }

. But since C is another language, there are other forces at work,
which means that the overall usability of such macros in C might not
make their definition and use worthwhile. Of course, the "smart" span
type in C++ surely can do more than my simple macros can do in C!

Re: "span"

<utjrbm$2st57$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34628&group=comp.lang.c#34628

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: thiago.a...@gmail.com (Thiago Adams)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Fri, 22 Mar 2024 08:51:18 -0300
Organization: A noiseless patient Spider
Lines: 84
Message-ID: <utjrbm$2st57$1@dont-email.me>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Mar 2024 11:51:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b69c71425e7b8f370ab82e463a5eae2f";
logging-data="3044519"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TYOCD+n0d5pcfSucotKlaMobe8lO5Rek="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fyhWOf4RbvvJrdHU8EuQWE83wi4=
In-Reply-To: <span-20240322122631@ram.dialup.fu-berlin.de>
Content-Language: en-US
 by: Thiago Adams - Fri, 22 Mar 2024 11:51 UTC

On 22/03/2024 08:30, Stefan Ram wrote:
> Some people suggested to introduce a feature "span" (probably a
> type) into C++, so that when one has an int array "a" and calls
> "f( a )", the length of a is being transferred to "f", which "f"
> is defined using "void f(span<int> a)". The "span" in "f" then
> knows the length of "a". This is supposed to be less error prone
> than passing a pointer with a separate length argument.
>
> Of course, I immediately wondered whether one could implement
> such a "span" for C, and here's a draft:
>
> #include <stdio.h>
>
> #define SPAN_PARAM(x,a,n) x*a,size_t const n
> #define SPAN(a) a,(sizeof a/sizeof 0[a])
>
> void print( SPAN_PARAM( int, a, n ))
> { for( size_t i = 0; i < n; ++i )
> printf( "%lld: %d\n", i, a[ i ]); }
>
> int main( void )
> { int a[ 3 ]={ 4, 6, 8 };
> print( SPAN(a) ); }
>
> . But since C is another language, there are other forces at work,
> which means that the overall usability of such macros in C might not
> make their definition and use worthwhile. Of course, the "smart" span
> type in C++ surely can do more than my simple macros can do in C!

(
C++ proposals use new type<T> instead of qualifiers. This creates a big
mess on the type system and incompatibility with C.
I don't have idea how/why they do this constantly.
)

C does not need this for parameters since the current array syntax
already cover that.

void f(int n, int a[n])

The problem is the syntax for pointers, this may be necessary in other
contexts other than in parameters.

C already have a syntax for pointer to array

int (*)[2] p;

The problem of this syntax is C code normally use pointer directly
and a pointer to array requires *p everywhere. Having an specific syntax
for pointer length makes the code transition from non-annotated to
annotated much easier. It also avoid lots of (*p)[index] and have just
p[index].

Does anyone have a suggestion for syntax to give pointers the length
information?

One try is

int *[2] p;

but the problem of this syntax is it is ambiguous with (cast)

(int *[2]) //pointer to 2 ints, or pointer to array of 2 ints

This alternative

(int [2]*)
is harder to parse since first it thinks it is array then it need fo
"fix" to be a pointer.

Re: "span"

<87edc1iyyg.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34665&group=comp.lang.c#34665

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 00:17:11 +0000
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <87edc1iyyg.fsf@bsb.me.uk>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4f3db932830b41078334f7d86415d5d6";
logging-data="3388512"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O9B8hcaIK0GUxBzACkiT4AEsx2dmLofI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:Z8F3bdTS1tZlclWRujmVu7KBtec=
sha1:CxrY9zGGY356llrAGapVP0lpQxM=
X-BSB-Auth: 1.d39ff5817c10538e53cc.20240323001711GMT.87edc1iyyg.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 23 Mar 2024 00:17 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Some people suggested to introduce a feature "span" (probably a
> type) into C++, so that when one has an int array "a" and calls
> "f( a )", the length of a is being transferred to "f", which "f"
> is defined using "void f(span<int> a)". The "span" in "f" then
> knows the length of "a". This is supposed to be less error prone
> than passing a pointer with a separate length argument.
>
> Of course, I immediately wondered whether one could implement
> such a "span" for C, and here's a draft:
>
> #include <stdio.h>
>
> #define SPAN_PARAM(x,a,n) x*a,size_t const n
> #define SPAN(a) a,(sizeof a/sizeof 0[a])

The usual reason given for writing 0[a] in a macro is so that
parentheses are not needed as they would be (recommended) for *(a) or
(a)[0]. But since you don't seem to care about writing a rather than
(a) I don't see why you wrote 0[a] rather than either *a or a[0].

> void print( SPAN_PARAM( int, a, n ))
> { for( size_t i = 0; i < n; ++i )
> printf( "%lld: %d\n", i, a[ i ]); }

What happens when print wants to pass 'a' to another function that takes
a span?

> int main( void )
> { int a[ 3 ]={ 4, 6, 8 };
> print( SPAN(a) ); }

--
Ben.

Re: "span"

<878r29iyvd.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34666&group=comp.lang.c#34666

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 00:19:02 +0000
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <878r29iyvd.fsf@bsb.me.uk>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="4f3db932830b41078334f7d86415d5d6";
logging-data="3388512"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0FyH90/5dkWP7ZsH8HwB/mchrKFun6MI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:tYUYpYd5/iHEDlR7lyhM2qsQHJk=
sha1:Om29qgJgNxOqPJ+7O+cN4SCh+8k=
X-BSB-Auth: 1.6fc869df3e2c56822019.20240323001902GMT.878r29iyvd.fsf@bsb.me.uk
 by: Ben Bacarisse - Sat, 23 Mar 2024 00:19 UTC

Thiago Adams <thiago.adams@gmail.com> writes:

> On 22/03/2024 08:30, Stefan Ram wrote:
>> Some people suggested to introduce a feature "span" (probably a
>> type) into C++, so that when one has an int array "a" and calls
>> "f( a )", the length of a is being transferred to "f", which "f"
>> is defined using "void f(span<int> a)". The "span" in "f" then
>> knows the length of "a". This is supposed to be less error prone
>> than passing a pointer with a separate length argument.
>> Of course, I immediately wondered whether one could implement
>> such a "span" for C, and here's a draft:
>> #include <stdio.h>
>> #define SPAN_PARAM(x,a,n) x*a,size_t const n
>> #define SPAN(a) a,(sizeof a/sizeof 0[a])
>> void print( SPAN_PARAM( int, a, n ))
>> { for( size_t i = 0; i < n; ++i )
>> printf( "%lld: %d\n", i, a[ i ]); }
>> int main( void )
>> { int a[ 3 ]={ 4, 6, 8 };
>> print( SPAN(a) ); }
>> . But since C is another language, there are other forces at work,
>> which means that the overall usability of such macros in C might not
>> make their definition and use worthwhile. Of course, the "smart" span
>> type in C++ surely can do more than my simple macros can do in C!
>
>
> (
> C++ proposals use new type<T> instead of qualifiers. This creates a big
> mess on the type system and incompatibility with C.
> I don't have idea how/why they do this constantly.
> )
>
> C does not need this for parameters since the current array syntax already
> cover that.
>
> void f(int n, int a[n])

Although you can't rely on this anymore since it's now an optional part
of the language.

....
> C already have a syntax for pointer to array
>
> int (*)[2] p;

I think you mean

int (*p)[2];

--
Ben.

Re: "span"

<20240322173153.95@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34668&group=comp.lang.c#34668

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 01:11:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <20240322173153.95@kylheku.com>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<87edc1iyyg.fsf@bsb.me.uk>
Injection-Date: Sat, 23 Mar 2024 01:11:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bc8ead67574eda43cc8acb80cc4a36a2";
logging-data="3423366"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GKyHUO4bfM0CZtyVs93GZGH/oRde/JMA="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:kZGkAV/kCigFbaWTaLYSFAyRexQ=
 by: Kaz Kylheku - Sat, 23 Mar 2024 01:11 UTC

On 2024-03-23, Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Some people suggested to introduce a feature "span" (probably a
>> type) into C++, so that when one has an int array "a" and calls
>> "f( a )", the length of a is being transferred to "f", which "f"
>> is defined using "void f(span<int> a)". The "span" in "f" then
>> knows the length of "a". This is supposed to be less error prone
>> than passing a pointer with a separate length argument.
>>
>> Of course, I immediately wondered whether one could implement
>> such a "span" for C, and here's a draft:
>>
>> #include <stdio.h>
>>
>> #define SPAN_PARAM(x,a,n) x*a,size_t const n
>> #define SPAN(a) a,(sizeof a/sizeof 0[a])
>
> The usual reason given for writing 0[a] in a macro is so that
> parentheses are not needed as they would be (recommended) for *(a) or
> (a)[0]. But since you don't seem to care about writing a rather than
> (a) I don't see why you wrote 0[a] rather than either *a or a[0].
>
>> void print( SPAN_PARAM( int, a, n ))
>> { for( size_t i = 0; i < n; ++i )
>> printf( "%lld: %d\n", i, a[ i ]); }
>
> What happens when print wants to pass 'a' to another function that takes
> a span?

How about linking the names of a and the size, like a and a_n?
Then we can make sure there is a _n size, whether we have an
array or pointer:

#include <stddef.h>
#include <stdio.h>

#define SPAN_DEF(type, a, size, init) \
type a[size] = init; const size_t a ## _n = size

#define SPAN_PARAM(type, a) \
type *a, size_t const a ## _n

#define SPAN(a) a, a ## _n

void print(SPAN_PARAM(int, a))
{
for (size_t i = 0; i < a_n; i++)
printf("%zd, %d\n", i, a[i]);
}

void print_wrap(SPAN_PARAM(int, a))
{
print(SPAN(a));
}

int main(void)
{
SPAN_DEF(int, a, 42, { 0 });
print_wrap(SPAN(a));
}

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: "span"

<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34680&group=comp.lang.c#34680

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: thiago.a...@gmail.com (Thiago Adams)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 11:16:08 -0300
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="ec21037bc3ec4e4b9a0b9f8b7520d837";
logging-data="3874623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PwIc0W9Ca3K4/iBrJymYQtSZz3K6ODAI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bqVDt9l8gEkI+YZ6fYb9dTkoIAA=
Content-Language: en-GB
In-Reply-To: <878r29iyvd.fsf@bsb.me.uk>
 by: Thiago Adams - Sat, 23 Mar 2024 14:16 UTC

Em 3/22/2024 9:19 PM, Ben Bacarisse escreveu:
> Thiago Adams <thiago.adams@gmail.com> writes:
>
>> On 22/03/2024 08:30, Stefan Ram wrote:
>>> Some people suggested to introduce a feature "span" (probably a
>>> type) into C++, so that when one has an int array "a" and calls
>>> "f( a )", the length of a is being transferred to "f", which "f"
>>> is defined using "void f(span<int> a)". The "span" in "f" then
>>> knows the length of "a". This is supposed to be less error prone
>>> than passing a pointer with a separate length argument.
>>> Of course, I immediately wondered whether one could implement
>>> such a "span" for C, and here's a draft:
>>> #include <stdio.h>
>>> #define SPAN_PARAM(x,a,n) x*a,size_t const n
>>> #define SPAN(a) a,(sizeof a/sizeof 0[a])
>>> void print( SPAN_PARAM( int, a, n ))
>>> { for( size_t i = 0; i < n; ++i )
>>> printf( "%lld: %d\n", i, a[ i ]); }
>>> int main( void )
>>> { int a[ 3 ]={ 4, 6, 8 };
>>> print( SPAN(a) ); }
>>> . But since C is another language, there are other forces at work,
>>> which means that the overall usability of such macros in C might not
>>> make their definition and use worthwhile. Of course, the "smart" span
>>> type in C++ surely can do more than my simple macros can do in C!
>>
>>
>> (
>> C++ proposals use new type<T> instead of qualifiers. This creates a big
>> mess on the type system and incompatibility with C.
>> I don't have idea how/why they do this constantly.
>> )
>>
>> C does not need this for parameters since the current array syntax already
>> cover that.
>>
>> void f(int n, int a[n])
>
> Although you can't rely on this anymore since it's now an optional part
> of the language.

I think it is back in c23.
But not vlas.

> ...
>> C already have a syntax for pointer to array
>>
>> int (*)[2] p;
>
> I think you mean
>
> int (*p)[2];
>
yes.

Re: "span"

<utnanu$2r0de$1@i2pn2.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34696&group=comp.lang.c#34696

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!.POSTED!not-for-mail
From: fir...@grunge.pl (fir)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 20:32:06 +0100
Organization: i2pn2 (i2pn.org)
Message-ID: <utnanu$2r0de$1@i2pn2.org>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Mar 2024 19:32:16 -0000 (UTC)
Injection-Info: i2pn2.org;
logging-data="2982318"; mail-complaints-to="usenet@i2pn2.org";
posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <span-20240322122631@ram.dialup.fu-berlin.de>
 by: fir - Sat, 23 Mar 2024 19:32 UTC

Stefan Ram wrote:
> Some people suggested to introduce a feature "span" (probably a
> type) into C++, so that when one has an int array "a" and calls
> "f( a )", the length of a is being transferred to "f", which "f"
> is defined using "void f(span<int> a)". The "span" in "f" then
> knows the length of "a". This is supposed to be less error prone
> than passing a pointer with a separate length argument.
>

i wrote on such thing for years here - i name it "full array"

i mean

int a[20] is "full array" when a is a structure of int* to begoning and
int* to end or length (there are natural two wersions and i tried both
though the one with pointer+_size is maybe more handy)

this foo(a) will pass this structure if a is full array - but this is to
be done on language and compiler level

what c got

int a[20] //when a is only int*

i name half-array

Re: "span"

<pan$4ba47$20b73398$89c6683d$d9bb1b67@invalid.invalid>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34698&group=comp.lang.c#34698

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 20:35:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <pan$4ba47$20b73398$89c6683d$d9bb1b67@invalid.invalid>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Mar 2024 20:35:11 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="e2f584ac85c2043cbd0d00bb403e1b5f";
logging-data="4038178"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xU7Ws05aolDjNxkKcpRyZBPD46SyLPQE="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:aQAniSYPjlylab9z7LMJSpFSIzE=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
X-Face: Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronuku
pokaiwhenuakitanatahu
 by: Blue-Maned_Hawk - Sat, 23 Mar 2024 20:35 UTC

Stefan Ram wrote:

> Some people suggested to introduce a feature "span" (probably a
> type) into C++, so that when one has an int array "a" and calls "f( a
> )", the length of a is being transferred to "f", which "f"
> is defined using "void f(span<int> a)". The "span" in "f" then knows
> the length of "a". This is supposed to be less error prone than
> passing a pointer with a separate length argument.
>
> Of course, I immediately wondered whether one could implement such a
> "span" for C, and here's a draft:
>
> #include <stdio.h>
>
> #define SPAN_PARAM(x,a,n) x*a,size_t const n #define SPAN(a) a,(sizeof
> a/sizeof 0[a])
>
> void print( SPAN_PARAM( int, a, n ))
> { for( size_t i = 0; i < n; ++i )
> printf( "%lld: %d\n", i, a[ i ]); }
>
> int main( void )
> { int a[ 3 ]={ 4, 6, 8 };
> print( SPAN(a) ); }
>
> . But since C is another language, there are other forces at work,
> which means that the overall usability of such macros in C might not
> make their definition and use worthwhile. Of course, the "smart" span
> type in C++ surely can do more than my simple macros can do in C!

You managed to inspire me to try my own hand at coming up with some macros
for spannage in C. By means of the library of macros P99 and the power of
C23, i ended up with this:

#define span(...) typeof (__VA_ARGS__) *
#define span_of(...) (((struct {const size_t length; typeof (__VA_ARGS__)
members
#define with_members(...) [P99_NARG(__VA_ARGS__)];})
{P99_NARG(__VA_ARGS__), {__VA_ARGS__}}).members)
#define span_length(...) (((struct {const size_t length; typeof
(__VA_ARGS__[0]) members[];} *)&(((char *)(__VA_ARGS__))[-sizeof
(size_t)]))->length)

This is used as such:

void f(const span(int) obj)
{ printf("%d, %d, %d, %zu", obj[1], obj[2], obj[5],
span_length(obj));
}

int main(void)
{ span(int) the_span = span_of(int) with_members(1,2,3,4,5,6);
printf("%d, %d, %d, %zu", the_span[1], the_span[2], the_span[5],
span_length(the_span));
return 0;
}

Now, you may notice that this, uh. doesn't actually work: the
with_members macro breaks if you're initializing the array with members
that have embedded commas in them. I tried to fix this, but my compiler
claimed that P99's P99_REMOVE_PAREN macro doesn't exist even though it
does.

On a tangent, the way that the typeof operator works in C23 means that
macros no longer have to worry about the fact that declarations such as
int(*)(int) x;
and
int[3] y;
don't work, meaning that they can accept any typename and use it raw
without needing the invoker to make a typedef.

--
Blue-Maned_Hawk│shortens to Hawk│/blu.mɛin.dʰak/│he/him/his/himself/Mr.
blue-maned_hawk.srht.site
The dark side of the C preprocessor is a path to many abilities, some
considered unnatural.

Re: "span"

<871q80zkg3.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34701&group=comp.lang.c#34701

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 14:50:52 -0700
Organization: None to speak of
Lines: 33
Message-ID: <871q80zkg3.fsf@nosuchdomain.example.com>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="82e56ab6d287cd951989ac0885bf2be2";
logging-data="4069322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yaomji8gkw+wTbhfhtBRF"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:qeb2e1nC31+ZR7aofdKIH/ckv10=
sha1:fuwVU8ZhgyQwgpkjfxtf9C1VKYM=
 by: Keith Thompson - Sat, 23 Mar 2024 21:50 UTC

Thiago Adams <thiago.adams@gmail.com> writes:
> Em 3/22/2024 9:19 PM, Ben Bacarisse escreveu:
>> Thiago Adams <thiago.adams@gmail.com> writes:
[...]
>>> void f(int n, int a[n])
>> Although you can't rely on this anymore since it's now an optional
>> part of the language.
>
> I think it is back in c23.
> But not vlas.
[...]

Correct.

From N1570 (the last public draft before C11):

__STDC_NO_VLA__ The integer constant 1, intended to indicate that
the implementation does not support variable length arrays or
variably modified types.

From N3220 (the first public draft of C26, essentially equivalent to C23):

__STDC_NO_VLA__ The integer constant 1, intended to indicate that
the implementation does not support variable length arrays with
automatic storage duration. Parameters declared with variable
length array types are adjusted and then define objects of
automatic storage duration with pointer types. Thus, support for
such declarations is mandatory.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: "span"

<87wmpsh0zy.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34704&group=comp.lang.c#34704

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sun, 24 Mar 2024 01:28:17 +0000
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <87wmpsh0zy.fsf@bsb.me.uk>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
<871q80zkg3.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ac39b37d4face64cd212e73c06f03235";
logging-data="4174104"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Tpo31CNOrKWQA7Fxl8s23c4CINUoTH1s="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:QCy1fGB/SH/VLtenMz672IMkmkU=
sha1:XRVAkGEkCh89ApKXAeHt9xmxeLo=
X-BSB-Auth: 1.5b8c499777fee4888e64.20240324012817GMT.87wmpsh0zy.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 24 Mar 2024 01:28 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Thiago Adams <thiago.adams@gmail.com> writes:
>> Em 3/22/2024 9:19 PM, Ben Bacarisse escreveu:
>>> Thiago Adams <thiago.adams@gmail.com> writes:
> [...]
>>>> void f(int n, int a[n])
>>> Although you can't rely on this anymore since it's now an optional
>>> part of the language.
>>
>> I think it is back in c23.
>> But not vlas.
> [...]
>
> Correct.
>
> From N1570 (the last public draft before C11):
>
> __STDC_NO_VLA__ The integer constant 1, intended to indicate that
> the implementation does not support variable length arrays or
> variably modified types.
>
> From N3220 (the first public draft of C26, essentially equivalent to C23):
>
> __STDC_NO_VLA__ The integer constant 1, intended to indicate that
> the implementation does not support variable length arrays with
> automatic storage duration. Parameters declared with variable
> length array types are adjusted and then define objects of
> automatic storage duration with pointer types. Thus, support for
> such declarations is mandatory.

Has C23 been ratified yet? The fact that there's a draft of C26
suggests it has been, but the news passed me by.

--
Ben.

Re: "span"

<87wmpsxtls.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34705&group=comp.lang.c#34705

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sat, 23 Mar 2024 19:15:59 -0700
Organization: None to speak of
Lines: 53
Message-ID: <87wmpsxtls.fsf@nosuchdomain.example.com>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
<871q80zkg3.fsf@nosuchdomain.example.com> <87wmpsh0zy.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="9dbe825be707a234cdd82aa198f8b427";
logging-data="2620"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jAagprKrCHyfGyHnvPclq"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:9upMx38OkKPmSNRtOzSY1KFg9aI=
sha1:btxVGYBnq1JXNiquxKb7TOiQtWI=
 by: Keith Thompson - Sun, 24 Mar 2024 02:15 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Thiago Adams <thiago.adams@gmail.com> writes:
>>> Em 3/22/2024 9:19 PM, Ben Bacarisse escreveu:
>>>> Thiago Adams <thiago.adams@gmail.com> writes:
>> [...]
>>>>> void f(int n, int a[n])
>>>> Although you can't rely on this anymore since it's now an optional
>>>> part of the language.
>>>
>>> I think it is back in c23.
>>> But not vlas.
>> [...]
>>
>> Correct.
>>
>> From N1570 (the last public draft before C11):
>>
>> __STDC_NO_VLA__ The integer constant 1, intended to indicate that
>> the implementation does not support variable length arrays or
>> variably modified types.
>>
>> From N3220 (the first public draft of C26, essentially equivalent to C23):
>>
>> __STDC_NO_VLA__ The integer constant 1, intended to indicate that
>> the implementation does not support variable length arrays with
>> automatic storage duration. Parameters declared with variable
>> length array types are adjusted and then define objects of
>> automatic storage duration with pointer types. Thus, support for
>> such declarations is mandatory.
>
> Has C23 been ratified yet? The fact that there's a draft of C26
> suggests it has been, but the news passed me by.

I don't believe it has.

According to <https://www.open-std.org/jtc1/sc22/wg14/>, "WG14 has
finished revising the C standard, under the name C23".

N3219, published 2024-02-22, is the Draft International Standard.
It's password-protected.

N3220, published the same day, is the C2y draft. My understanding is
that its content is very nearly indentical to N3219. I don't know what
changes are possible or likely between N3219 and the upcoming C23
standard.

https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: "span"

<87msqnhojt.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34708&group=comp.lang.c#34708

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Sun, 24 Mar 2024 11:11:50 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <87msqnhojt.fsf@bsb.me.uk>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
<871q80zkg3.fsf@nosuchdomain.example.com> <87wmpsh0zy.fsf@bsb.me.uk>
<87wmpsxtls.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="ac39b37d4face64cd212e73c06f03235";
logging-data="336260"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xZ1HncC5ykNrwmX9Yp24O3OEEjIFrfnk="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:/elRQJw2avSWZO2AoIptmthSFbA=
sha1:0hALPA3zOZlKZfwoU17zGUrlWMM=
X-BSB-Auth: 1.0a1aae7d0f8de97a72fb.20240324111150GMT.87msqnhojt.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 24 Mar 2024 11:11 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
....
>> Has C23 been ratified yet? The fact that there's a draft of C26
>> suggests it has been, but the news passed me by.
>
> I don't believe it has.
>
> According to <https://www.open-std.org/jtc1/sc22/wg14/>, "WG14 has
> finished revising the C standard, under the name C23".
>
> N3219, published 2024-02-22, is the Draft International Standard.
> It's password-protected.
>
> N3220, published the same day, is the C2y draft. My understanding is
> that its content is very nearly indentical to N3219. I don't know what
> changes are possible or likely between N3219 and the upcoming C23
> standard.
>
> https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log

Thanks.

--
Ben.

Re: "span"

<utqhtu$m76o$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34745&group=comp.lang.c#34745

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: "span"
Date: Mon, 25 Mar 2024 00:53:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <utqhtu$m76o$2@dont-email.me>
References: <span-20240322122631@ram.dialup.fu-berlin.de>
<utjrbm$2st57$1@dont-email.me> <878r29iyvd.fsf@bsb.me.uk>
<88f3b4c1-6dad-4fec-8941-fc4e4e755cd1@gmail.com>
<871q80zkg3.fsf@nosuchdomain.example.com> <87wmpsh0zy.fsf@bsb.me.uk>
<87wmpsxtls.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Mar 2024 01:53:19 +0100
Injection-Info: dont-email.me; posting-host="34f2761dc63506c4d9000838186fb572";
logging-data="728280"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18T/PZZbEPpXVXks/vw6l9L"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:k/Mhm0HxLqtbTK3/CvKCAPD7CgA=
 by: Lawrence D'Oliv - Mon, 25 Mar 2024 00:53 UTC

On Sat, 23 Mar 2024 19:15:59 -0700, Keith Thompson wrote:

> N3219, published 2024-02-22, is the Draft International Standard.
> It's password-protected.

Didn’t take much of a search to find the password ...

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor