Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If the code and the comments disagree, then both are probably wrong. -- Norm Schryer


devel / comp.lang.c / Re: I think references should have been const by default

SubjectAuthor
o Re: I think references should have been const by defaultJames Kuyper

1
Re: I think references should have been const by default

<sl9hj7$uir$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: I think references should have been const by default
Date: Tue, 26 Oct 2021 14:32:06 -0400
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <sl9hj7$uir$1@dont-email.me>
References: <skqtfl$17n5$1@gioia.aioe.org> <skr2r3$81j$1@dont-email.me>
<skrd0t$1p75$1@gioia.aioe.org> <skrh21$ksj$1@dont-email.me>
<skrqki$obd$1@gioia.aioe.org> <skrs1e$co2$1@dont-email.me>
<sktq8m$7ht$1@dont-email.me> <skuj0p$t60$1@dont-email.me>
<sl0nmu$bn3$1@dont-email.me> <sl0qcj$sub$1@dont-email.me>
<sl1e73$sl7$1@dont-email.me> <sl5pdi$4au$1@gioia.aioe.org>
<sl5ug4$qov$1@gioia.aioe.org> <sl6ecq$11uu$1@gioia.aioe.org>
<sl6go4$pjq$1@dont-email.me> <sl6l56$10d6$1@gioia.aioe.org>
<sl6oln$odm$1@dont-email.me> <sl8dlg$nav$1@gioia.aioe.org>
<sl93ge$fne$1@dont-email.me> <sl944f$1qlh$1@gioia.aioe.org>
<sl96fa$7q9$1@dont-email.me> <sl96ut$1a96$1@gioia.aioe.org>
<sl9a29$438$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Oct 2021 18:32:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="456c19f5d2ca24044c8f8bf0b2cef6b1";
logging-data="31323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WWwvBO3oLexl1ykm3WDmXN/0cbVw1NyU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:XEXBtMq/toKa6eLWZVWkF5kxmGc=
In-Reply-To: <sl9a29$438$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Tue, 26 Oct 2021 18:32 UTC

On 10/26/21 12:23 PM, James Kuyper wrote:
....
> No, I said "it's not permitted to declare functions that take arrays as
> arguments, but it is permitted to declare a function parameter as if it
> were an array."
>
> Such a declaration does NOT declare the parameter to be an array, it
> declares it to be a pointer. You've retained my citation of the part of
> the standard that says so above. Here's a complete compilable program
> demonstrating that rule:
>
> #include <stdio.h>
>
> static void func(int a[2][3])
> {
> printf("%s\n",
> _Generic(a, int[2][3]: "array", int(*)[3]: "pointer"));
> }
>
> int main(void)
> {
> int a[2][3];
> func(a);
> }
>
> When I run that program, it says "pointer". What do you get when you run it?

Unfortunately, that doesn't prove what I intended it to prove, because
even if a were an array, it would have been converted to a pointer when
passed to _Generic. That problem is not too difficult to work around, I
just have to use the '&' operator:

#include <stdio.h>

#define ARR_PTR(x) _Generic(&x, \
int(*)[2][3]: "array", \
int(**)[3]: "pointer", \
default: "other")

static void func(int a[2][3])
{
int b[2][3];
int (*c)[3];
printf("a:%s\n", ARR_PTR(a));
printf("b:%s\n", ARR_PTR(b));
printf("c:%s\n", ARR_PTR(c));
}

int main(void)
{
int a[2][3];
func(a);
}

I get the following output:
a:pointer
b:array
c:pointer

What do you get?

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor