Re: Struct Error

Liste des GroupesRevenir à cl c 
Sujet : Re: Struct Error
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 26. Jan 2025, 20:14:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vn61ho$1pf2$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 24/01/2025 14:37, Michael S wrote:
On Thu, 23 Jan 2025 10:54:10 +0000
bart <bc@freeuk.com> wrote:
 
On 23/01/2025 01:05, James Kuyper wrote:
On 2025-01-22, bart <bc@freeuk.com> wrote:
Gcc 14.1 gives me an error compiling this code:
>
     struct vector;
     struct scenet;
>
     struct vector {
         double x;
         double y;
         double z;
     };
>
     struct scenet {
         struct vector center;
         double radius;
         struct scenet (*child)[];
     };
>
6.7.6.2p2: "The element type shall not be an incomplete or function
type."
>
I have many draft versions of the C standard. n2912.pdf, dated
2022-06-08, says in 6.7.2.1.p3 about struct types that "... the
type is incomplete144) until immediately after the closing brace of
the list defining the content, and complete thereafter."
>
Therefore, struct scenet is not a complete type until the closing
brace of it's declaration.
>
Wouldn't this also be the case here:
>
     struct scenet *child;
    };
>
 Just to point out if it was not said already: the problem is not related
specifically to recursive structures. It applies to arrays of
incomplete types in all circumstances.
 struct bar;
struct bar (*bag)[]; // error
typedef struct bar (*bat)[]; // error
I don't think anyone has yet explained why that is an error (other than C says it is), but not this:
   struct bar *ptr;
This is a pointer to an incomplete type. Attempts to do ++ptr for example will fail later on if that struct has not yet been defined.
So why not the same for the pointer-to-array versions?
It just doesn't make sense.
Is it just because such pointers HAVE to work, otherwise self-referential structs become impossible? That would make it a hack, in which case why not apply it to arrays too?

The case of the recursive structure is special only in a sense that it's
o.k. in C++, because [unlike C] in C++ struct considered complete within
its own body.
For non-recursive, you can choose to declare the pointer-to-array after the struct has been fully defined.

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