Re: Struct Error

Liste des GroupesRevenir à cl c 
Sujet : Re: Struct Error
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 24. Jan 2025, 21:31:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250124122425.242@kylheku.com>
References : 1 2 3 4 5 6
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-01-24, David Brown <david.brown@hesbynett.no> wrote:
On 24/01/2025 01:51, bart wrote:
 
No, both of these need to know the size of the struct when accessing the
i'th element:
 
   ....
    struct scenet *childp;
    struct scenet (*childa)[];
  };
 
The only thing you can't do with x->childa is perform pointer arithmetic
on the whole pointer-to-array, since the array size is zero. But doing
(x->childa)[i] should be fine.
 
As is clear since other compilers (excluding those that lavishly copy
gcc's behaviour) have no problem with it.
 
 
This is one of these cases where the C language /could/ have been
defined to allow incomplete types to be used.  But the language
definition (the standards) does not allow it.

It does; the implementation can issue a required diagnostic,
and keep chugging along. The behavior becomes undefined, but
the same implementation can provide its own definition:
like such that when the type is completed by the time it
matters, it's all good.

The language definition only does not allow the implementation to be
called conforming if it doesn't diagnose the usage, and doesn't allow
the program's behavior to be well-defined ISO C.

1. Should future C standards be modified to be more lenient in the code
the accept?  Was there a good reason for these limitations, and is that
reason still valid?

In this particular matter, GNU C++ accepts the code. If that happens to
be because of how ISO C++ is defined, then that carries substantial
weight. Why should C require a diagnostic in something that C++
allows to pass.  (C++, whose C-like subset is touted as a "safer C"!)

Speaking of which, Bart never responded to the workaround I found,
namely that g++ accepts his code.

I'm guessing it's too abhorrent to even think about, like inviting the
occasional blasphemer into a satanic cult.

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

Date Sujet#  Auteur
22 Jan 25 * Struct Error38bart
22 Jan 25 +* Re: Struct Error2Kaz Kylheku
22 Jan 25 i`- Re: Struct Error1Ben Bacarisse
22 Jan 25 +- Re: Struct Error1Richard Harnden
22 Jan 25 +- Re: Struct Error1Lawrence D'Oliveiro
23 Jan 25 +* Re: Struct Error31James Kuyper
23 Jan 25 i+* Re: Struct Error3m137
23 Jan 25 ii+- Re: Struct Error1Tim Rentsch
23 Jan 25 ii`- Re: Struct Error1James Kuyper
23 Jan 25 i+- Re: Struct Error1Tim Rentsch
23 Jan 25 i`* Re: Struct Error26bart
23 Jan 25 i +* Re: Struct Error9BGB
24 Jan 25 i i`* Re: Struct Error8bart
24 Jan 25 i i +- Re: Struct Error1BGB
24 Jan 25 i i +* Re: Struct Error4David Brown
24 Jan 25 i i i`* Re: Struct Error3Kaz Kylheku
24 Jan 25 i i i +- Re: Struct Error1bart
25 Jan 25 i i i `- Re: Struct Error1James Kuyper
24 Jan 25 i i `* Re: Struct Error2James Kuyper
25 Jan 25 i i  `- Re: Struct Error1bart
24 Jan 25 i +* Re: Struct Error5Lawrence D'Oliveiro
24 Jan 25 i i`* Re: Struct Error4bart
24 Jan 25 i i `* Re: Struct Error3Lawrence D'Oliveiro
24 Jan 25 i i  +- Re: Struct Error1Keith Thompson
24 Jan 25 i i  `- Re: Struct Error1bart
24 Jan 25 i +- Re: Struct Error1James Kuyper
24 Jan 25 i `* Re: Struct Error10Michael S
26 Jan 25 i  `* Re: Struct Error9bart
26 Jan 25 i   +- Re: Struct Error1Michael S
27 Jan 25 i   +* Re: Struct Error2Kaz Kylheku
27 Jan 25 i   i`- Re: Struct Error1bart
29 Jan 25 i   `* Re: Struct Error5Tim Rentsch
29 Jan 25 i    +* Re: Struct Error2bart
30 Jan 25 i    i`- Re: Struct Error1Tim Rentsch
29 Jan 25 i    `* Re: Struct Error2Richard Damon
29 Jan 25 i     `- Re: Struct Error1Tim Rentsch
23 Jan 25 +- Re: Struct Error1Tim Rentsch
3 Feb 25 `- Re: Struct Error1Andrey Tarasevich

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal