Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Remember, there's a big difference between kneeling down and bending over. -- Frank Zappa


devel / comp.std.c / int n = {{0}};

SubjectAuthor
* int n = {{0}};Keith Thompson
+- Re: int n = {{0}};Richard Damon
`* Re: int n = {{0}};Tim Rentsch
 `* Re: int n = {{0}};Keith Thompson
  `- Re: int n = {{0}};Tim Rentsch

1
int n = {{0}};

<8734xwkc1c.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.std.c
Subject: int n = {{0}};
Date: Thu, 26 Oct 2023 19:57:19 -0700
Organization: None to speak of
Lines: 51
Message-ID: <8734xwkc1c.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="7ab2f2b489eaca4d293095b514b3d94e";
logging-data="2194295"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q3TKSCKdQccfv9b1qjISK"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:mmEjKILPlZddMkiRuZje73DIVFA=
sha1:Zk3eWJlejJe+25qCD/5PJRDn6e0=
 by: Keith Thompson - Fri, 27 Oct 2023 02:57 UTC

Citations are from N1570 (C11 draft). I don't think there are any
relevant differences in other editions or drafts of the standard.

Quick summary: Why is
int n = {{0}};
undefined behavior rather than a constraint violation?

6.7.9 (Initialization) includes a list of constraints, starting with "No
initializer shall attempt to provide a value for an object not contained
within the entity being initialized."

6.7.9p11 says:

The initializer for a scalar shall be a single expression,
optionally enclosed in braces. The initial value of the object is
that of the expression (after conversion); the same type constraints
and conversions as for simple assignment apply, taking the type of
the scalar to be the unqualified version of its declared type.

(I presume that "optionally enclosed in braces" is not intended to permit
more than one level of braces.)

Both
int n = 0;
and
int n = {0};
are clearly valid, with identical semantics. But this:
int n = {{0}};
violates that requirement. Since the requirement is under Semantics,
not Constraints, code that violates it has undefined behavior. Starting
with C99, this is mentioned in Annex J.

My question: Why is this undefined behavior rather than a constraint
violation?

I suggest that moving that paragraph from Semantics to Constraints would
be an improvement. Extra braces on a scalar initializer are easy to
detect, and requiring a diagnostic should not be a significant burden,
and would promote consistency. (Alternatively, the standard could have
explicitly allowed arbitrarily nested braces.)

With the current requirements, a compiler could quietly generate code to
set n to 42, though I doubt that anyone would do that.

(I note that gcc issues a non-fatal warning with "-std=c17
-pedantic-errors", while clang treats it as a fatal error.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: int n = {{0}};

<kRa%M.330599$w4ec.60402@fx14.iad>

  copy mid

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

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: int n = {{0}};
Content-Language: en-US
Newsgroups: comp.std.c
References: <8734xwkc1c.fsf@nosuchdomain.example.com>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <8734xwkc1c.fsf@nosuchdomain.example.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 53
Message-ID: <kRa%M.330599$w4ec.60402@fx14.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 28 Oct 2023 09:41:51 -0700
X-Received-Bytes: 3012
 by: Richard Damon - Sat, 28 Oct 2023 16:41 UTC

On 10/26/23 7:57 PM, Keith Thompson wrote:
> Citations are from N1570 (C11 draft). I don't think there are any
> relevant differences in other editions or drafts of the standard.
>
> Quick summary: Why is
> int n = {{0}};
> undefined behavior rather than a constraint violation?
>
> 6.7.9 (Initialization) includes a list of constraints, starting with "No
> initializer shall attempt to provide a value for an object not contained
> within the entity being initialized."
>
> 6.7.9p11 says:
>
> The initializer for a scalar shall be a single expression,
> optionally enclosed in braces. The initial value of the object is
> that of the expression (after conversion); the same type constraints
> and conversions as for simple assignment apply, taking the type of
> the scalar to be the unqualified version of its declared type.
>
> (I presume that "optionally enclosed in braces" is not intended to permit
> more than one level of braces.)
>
> Both
> int n = 0;
> and
> int n = {0};
> are clearly valid, with identical semantics. But this:
> int n = {{0}};
> violates that requirement. Since the requirement is under Semantics,
> not Constraints, code that violates it has undefined behavior. Starting
> with C99, this is mentioned in Annex J.
>
> My question: Why is this undefined behavior rather than a constraint
> violation?
>
> I suggest that moving that paragraph from Semantics to Constraints would
> be an improvement. Extra braces on a scalar initializer are easy to
> detect, and requiring a diagnostic should not be a significant burden,
> and would promote consistency. (Alternatively, the standard could have
> explicitly allowed arbitrarily nested braces.)
>
> With the current requirements, a compiler could quietly generate code to
> set n to 42, though I doubt that anyone would do that.
>
> (I note that gcc issues a non-fatal warning with "-std=c17
> -pedantic-errors", while clang treats it as a fatal error.)
>

I wonder a bit if this is bowing to conflicting existing
implementations. So were giving a fatal error for the extra braces,
while some specifically permitted them, and have a measurable code base
that uses that permision.

Re: int n = {{0}};

<86cyvnw0n4.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: int n = {{0}};
Date: Sun, 03 Dec 2023 11:23:43 -0800
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <86cyvnw0n4.fsf@linuxsc.com>
References: <8734xwkc1c.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="8fbbb635fc34c7b6e7854189caff33a4";
logging-data="3144743"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/M6fZp6rAzKUdAyVbNURxV7S6ETZXAFE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qMTtqM98FDglz6T4WqLBp8J2Ntc=
sha1:tBMvtO81+hZxVBW8W+hxiIZPjDY=
 by: Tim Rentsch - Sun, 3 Dec 2023 19:23 UTC

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

> Citations are from N1570 (C11 draft). I don't think there are any
> relevant differences in other editions or drafts of the standard.
>
> Quick summary: Why is
> int n = {{0}};
> undefined behavior rather than a constraint violation?

Because there is no practical benefit to changing what the
standard says now.

> 6.7.9 (Initialization) includes a list of constraints, starting
> with "No initializer shall attempt to provide a value for an
> object not contained within the entity being initialized."
>
> 6.7.9p11 says:
>
> The initializer for a scalar shall be a single expression,
> optionally enclosed in braces. The initial value of the
> object is that of the expression (after conversion); the same
> type constraints and conversions as for simple assignment
> apply, taking the type of the scalar to be the unqualified
> version of its declared type.
>
> (I presume that "optionally enclosed in braces" is not intended to
> permit more than one level of braces.)
>
> Both
> int n = 0;
> and
> int n = {0};
> are clearly valid, with identical semantics. But this:
> int n = {{0}};
> violates that requirement. Since the requirement is under
> Semantics, not Constraints, code that violates it has undefined
> behavior. Starting with C99, this is mentioned in Annex J.
>
> My question: Why is this undefined behavior rather than a
> constraint violation?

There's no practical benefit to changing it. The current rule
has been in place since the original ANSI C standard, more than
30 years ago. Whatever the motivation may have been at that
time, there is no incentive to change the rules now; compilers
already give diagnostics in such cases, even though they don't
have to. Changing the rules would mean throwing away a degree
of freedom with no significant benefit.

> I suggest that moving that paragraph from Semantics to Constraints
> would be an improvement. Extra braces on a scalar initializer are
> easy to detect,

All work is easy if it's someone else who is doing it. Certainly
it would be easier just to leave things as is.

> and requiring a diagnostic should not be a significant burden,

This statement assumes other people have the same reaction that
you do. Not everyone does.

> and would promote consistency. [...]

There is already consistency. There is no evidence to suggest
that changing the standard would make a difference at all to what
code people write. Most people are driven by what warnings or
errors they get, and compilers already give these messages.

> With the current requirements, a compiler could quietly generate
> code to set n to 42, though I doubt that anyone would do that.

If such forms were constraint violations, compilers could give a
warning (which they already do), and then generate code to set n
to 42. In practical terms there is no difference from the
current situation.

> (I note that gcc issues a non-fatal warning with "-std=c17
> -pedantic-errors", while clang treats it as a fatal error.)

If anyone absolutely wants a diagnostic, they can simply compile
with gcc or clang.

Note that clang has a compiler option to turn off the diagnostic
for such cases. Presumably that option is there because some
people want to use it. Making double braces a constraint violation
would interfere with what they want to do. What is suggested as an
improvement looks like all downside and no upside.

Re: int n = {{0}};

<878r6b3q0o.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.std.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.std.c
Subject: Re: int n = {{0}};
Date: Sun, 03 Dec 2023 14:00:39 -0800
Organization: None to speak of
Lines: 35
Message-ID: <878r6b3q0o.fsf@nosuchdomain.example.com>
References: <8734xwkc1c.fsf@nosuchdomain.example.com>
<86cyvnw0n4.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f2a47b77cfc24e924416c84c84ca6a31";
logging-data="3205152"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198Hiy7ke6NtZa6ljS4NLEW"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:mpmyWuu+zYuJ4o6hxy91TlceteQ=
sha1:3NiNoGaOozDybNroM3rjcaqT7LM=
 by: Keith Thompson - Sun, 3 Dec 2023 22:00 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Citations are from N1570 (C11 draft). I don't think there are any
>> relevant differences in other editions or drafts of the standard.
>>
>> Quick summary: Why is
>> int n = {{0}};
>> undefined behavior rather than a constraint violation?
>
> Because there is no practical benefit to changing what the
> standard says now.

Do you have an opinion about whether it should have been specified as a
constraint violation rather than undefined behavior in the first place?

[...]

> There's no practical benefit to changing it. The current rule
> has been in place since the original ANSI C standard, more than
> 30 years ago. Whatever the motivation may have been at that
> time, there is no incentive to change the rules now; compilers
> already give diagnostics in such cases, even though they don't
> have to. Changing the rules would mean throwing away a degree
> of freedom with no significant benefit.

It would remove a degree of freedom for implementers, one that few if
any currently take advantage of. Meaningless degrees of freedom for
implementers do not help users.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: int n = {{0}};

<86jzo6jdic.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: int n = {{0}};
Date: Thu, 18 Jan 2024 17:52:27 -0800
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <86jzo6jdic.fsf@linuxsc.com>
References: <8734xwkc1c.fsf@nosuchdomain.example.com> <86cyvnw0n4.fsf@linuxsc.com> <878r6b3q0o.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="4317632f5246f6fddd21ccc8d476a409";
logging-data="2982580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zUQtH5SWkMSn6D8nF0eHB31UqAAq8vSY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:/le1t6Q9cWoSQDX7PAxs9FFq7Nw=
sha1:dVY9hcexwRFGMWrKGVm8q1iTF2w=
 by: Tim Rentsch - Fri, 19 Jan 2024 01:52 UTC

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

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> Citations are from N1570 (C11 draft). I don't think there are any
>>> relevant differences in other editions or drafts of the standard.
>>>
>>> Quick summary: Why is
>>> int n = {{0}};
>>> undefined behavior rather than a constraint violation?
>>
>> Because there is no practical benefit to changing what the
>> standard says now.
>
> Do you have an opinion about whether it should have been specified as a
> constraint violation rather than undefined behavior in the first place?

I don't have any pertinent information on which to base such an
opinion. It's possible there was existing code that prompted
what decision was made at the time. It's also possible that what
was done is just the result of an oversight. I'm inclined to think
that there was some reasoning that led to what was actually done
(ie, that there is undefined behavior but no constraint violation),
but that's just a general impression, not based on any specific
facts. If there was such reasoning, then without more information
I would tend to favor supporting it.

I guess I could add that there are other constructions in C that
are undefined behavior, and are identifiable at compile time, but
which are not constraint violations, and I think that's the right
decision for at least some of them.

>> There's no practical benefit to changing it. The current rule
>> has been in place since the original ANSI C standard, more than
>> 30 years ago. Whatever the motivation may have been at that
>> time, there is no incentive to change the rules now; compilers
>> already give diagnostics in such cases, even though they don't
>> have to. Changing the rules would mean throwing away a degree
>> of freedom with no significant benefit.
>
> It would remove a degree of freedom for implementers, one that
> few if any currently take advantage of.

As I mentioned in my earlier post, the clang compiler does take
advantage of this particular degree of freedom, with an option to
turn off diagnostics corresponding to such cases.

> Meaningless degrees of freedom for implementers do not help
> users.

I infer from the existence of the clang option that some people
think the degree of freedom here is both meaningful and useful.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor