Deutsch   English   Français   Italiano  
<20250124163740.00006281@yahoo.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.lang.c
Subject: Re: Struct Error
Date: Fri, 24 Jan 2025 16:37:40 +0200
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20250124163740.00006281@yahoo.com>
References: <vmr5gg$137jo$1@dont-email.me>
	<vms4km$19srg$1@dont-email.me>
	<vmt74h$1jac0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 24 Jan 2025 15:37:44 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1a3bf6e0363845c200608d71f04f46bf";
	logging-data="2334323"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19aFLAas6Eeg8aWWe2dthxRjy5jdDsg9Jc="
Cancel-Lock: sha1:qb6qJ2bjxC5p55TjjnhyAg1dVbI=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)
Bytes: 2553

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

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.