Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Real Users are afraid they'll break the machine -- but they're never afraid to break your face.


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

SubjectAuthor
* Why are VLAs optional in C11?pdx_scooter@yahoo.com
`- Why are VLAs optional in C11?Keith Thompson

1
Re: Why are VLAs optional in C11?

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=862&group=comp.std.c#862

  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_scooter@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://news.novabbs.org/devel/article-flat.php?id=863&group=comp.std.c#863

  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.Thompson+u@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 */

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor