Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The study of non-linear physics is like the study of non-elephant biology.


devel / comp.std.c / Re: Why are VLAs optional in C11?

SubjectAuthor
* Re: Why are VLAs optional in C11?pdx_scooter@yahoo.com
+- Re: Why are VLAs optional in C11?Keith Thompson
`- Re: Why are VLAs optional in C11?Tomasz Stanislawski

1
Re: Why are VLAs optional in C11?

<fb07c002-cf76-4063-b720-999e3a2ded91n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.std.c
X-Received: by 2002:a05:6214:29ea:b0:4ad:8743:699a with SMTP id jv10-20020a05621429ea00b004ad8743699amr11977560qvb.44.1664655302119;
Sat, 01 Oct 2022 13:15:02 -0700 (PDT)
X-Received: by 2002:a05:6870:fb90:b0:131:db1f:7785 with SMTP id
kv16-20020a056870fb9000b00131db1f7785mr1970275oab.189.1664655301874; Sat, 01
Oct 2022 13:15:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.std.c
Date: Sat, 1 Oct 2022 13:15:01 -0700 (PDT)
In-Reply-To: <k0o22h$5ni$1@speranza.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:bac0:6b30:b1cf:40e6:9d9:7d17;
posting-account=20HSMAoAAACGQg1hSm9i3NOcqgRlWA3_
NNTP-Posting-Host: 2600:1700:bac0:6b30:b1cf:40e6:9d9:7d17
References: <lnfw7lnnrh.fsf@nuthaus.mib.org> <502ED178.50603@loria.fr>
<k0n48g$tsc$1@dont-email.me> <k0o22h$5ni$1@speranza.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fb07c002-cf76-4063-b720-999e3a2ded91n@googlegroups.com>
Subject: Re: Why are VLAs optional in C11?
From: pdx_scoo...@yahoo.com (pdx_scooter@yahoo.com)
Injection-Date: Sat, 01 Oct 2022 20:15:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3160
 by: pdx_scooter@yahoo.co - Sat, 1 Oct 2022 20:15 UTC

On Saturday, August 18, 2012 at 5:33:19 AM UTC-7, jacob navia wrote:

> In my implementation [of VLA parameters] I had a REAL sizeof that will return the actual
> size. I was told to replace it, but I think I will not.

An implementation of sizeof that returns something other than the size of the pointer when given a VLA parameter violates the fundamental rules of C pointer arithmetic. You cannot pass an array to a function in C, except by wrapping a struct or union around it. Confusingly, C allows you to write function parameters that -appear- to be arrays, e.g.

int main(int argc, char *argv[]) // misleading declaration: argv is NOT an array; rather, it's merely a vector

The compiler knows that an array cannot be passed directly to a function because any time an expression of type array of X appears in expression context (e.g. the actual parameter in a function call), the compiler promotes the type to pointer to X by taking the address of the first element. So when the compiler sees an array type in a parameter list, it silently re-writes it to what it really is:

int main(int argc, char **argv)

This is a throw-back to pre-ANSI C when the compiler would also silently re-write formal parameters of type "char" and "short" to "int" and "float" to "double". It's too bad ANSI C didn't disallow writing parameters that appear incorrectly as array types, but the fact that they didn't made VLA parameters possible.

In my example, regardless of which declaration I use for argv, argv is a pointer in every way. For example, we can say ++argv. We wouldn't be able to increment it if it were an array.

The VLA parameter is similarly silently rewritten as a pointer type, and just as above, when we have:

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

We can say ++a inside the function.

Re: Why are VLAs optional in C11?

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

  copy mid

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

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.std.c
Subject: Re: Why are VLAs optional in C11?
Date: Sat, 01 Oct 2022 14:33:14 -0700
Organization: None to speak of
Lines: 20
Message-ID: <87sfk7kz51.fsf@nosuchdomain.example.com>
References: <lnfw7lnnrh.fsf@nuthaus.mib.org> <502ED178.50603@loria.fr>
<k0n48g$tsc$1@dont-email.me> <k0o22h$5ni$1@speranza.aioe.org>
<fb07c002-cf76-4063-b720-999e3a2ded91n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="061fb2a259e6ca7edd5ef8a69428d610";
logging-data="1508398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lGBxNYFUltRJeDtyduXGU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:vKglBqGF4Iqt/hJn8puy01vyIzI=
sha1:XgUVMlxwZ+i6RdfDfWHoRmM5bi8=
 by: Keith Thompson - Sat, 1 Oct 2022 21:33 UTC

"pdx_scooter@yahoo.com" <pdx_scooter@yahoo.com> writes:
> On Saturday, August 18, 2012 at 5:33:19 AM UTC-7, jacob navia wrote:
>
>> In my implementation [of VLA parameters] I had a REAL sizeof that will return the actual
>> size. I was told to replace it, but I think I will not.
>
> An implementation of sizeof that returns something other than the size
> of the pointer when given a VLA parameter violates the fundamental
> rules of C pointer arithmetic.
[...]

Agreed.

Are you aware that you just replied to an article that was posted 10
years ago?

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

Re: Why are VLAs optional in C11?

<b0303ff9-5b09-49c0-bd44-13448d594c33n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.std.c
X-Received: by 2002:ac8:54b:0:b0:3a9:7ff3:3239 with SMTP id c11-20020ac8054b000000b003a97ff33239mr929686qth.351.1674649291823;
Wed, 25 Jan 2023 04:21:31 -0800 (PST)
X-Received: by 2002:aca:5882:0:b0:35b:75b:f3b9 with SMTP id
m124-20020aca5882000000b0035b075bf3b9mr1680000oib.98.1674649291584; Wed, 25
Jan 2023 04:21:31 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.std.c
Date: Wed, 25 Jan 2023 04:21:31 -0800 (PST)
In-Reply-To: <fb07c002-cf76-4063-b720-999e3a2ded91n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=95.160.22.43; posting-account=yFtgsgoAAADuoYDgjY7SYIzvTu5RXv3O
NNTP-Posting-Host: 95.160.22.43
References: <lnfw7lnnrh.fsf@nuthaus.mib.org> <502ED178.50603@loria.fr>
<k0n48g$tsc$1@dont-email.me> <k0o22h$5ni$1@speranza.aioe.org> <fb07c002-cf76-4063-b720-999e3a2ded91n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b0303ff9-5b09-49c0-bd44-13448d594c33n@googlegroups.com>
Subject: Re: Why are VLAs optional in C11?
From: stanisla...@googlemail.com (Tomasz Stanislawski)
Injection-Date: Wed, 25 Jan 2023 12:21:31 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1793
 by: Tomasz Stanislawski - Wed, 25 Jan 2023 12:21 UTC

> void f(int n, int a[n])
>
> We can say ++a inside the function.

There is some debate if it is an actual VLA type. The standard requires to transform the declaration of `int a[n]` to `int* a`.
To my understanding, the original VLA type is erased during at function's *definition* and its top-level size expression should not never be evaluated.
The situation is different while passing a pointer to an array:

```
void f(int n, int (*a)[n]) { ... }
```

Now, `n` must be evaluated at every invocation of the function.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor