Re: Struct Error

Liste des GroupesRevenir à cl c 
Sujet : Re: Struct Error
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 27. Jan 2025, 21:19:13
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vn8po2$172j1$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
On 27/01/2025 04:05, Kaz Kylheku wrote:
On 2025-01-26, bart <bc@freeuk.com> wrote:
On 24/01/2025 14:37, Michael S wrote:
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.
 You already know that GNU C++ silently accepts it, so this is
beating a dead horse.
C++ is no good to me. My old transpiler (now a deprecated product anyway) generated C. Fixing it either means updating the transpiler (and finding some hacky workaround like using casts everywhere) or doing that manually to the generated C. Neither appeal.

Your situation is this:
    struct incomplete {
     struct incomplete (*parray)[];
   };
 If we make a pointer to a struct rather than array,
it's the same kind of problem:
    struct incomplete {
     struct nested_incomplete {
       struct incomplete memb;
     } *pstruct;
   };
 In both cases, we have a pointer to something which
has an element, or member, of the incomplete type of
the outer struct which is to contain the pointer.
It's trickier problem: I'm not sure myself what the size should be, whereas that was easy to see with my array example. Here even TCC reports it as incomplete. How my C compiler tells me the size is 8 bytes, which sounds reasonable given that the only concrete member in there is one 64-bit pointer.

If the array version should work, so should the
struct version.
 
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.
 If a C++ struct is complete within its own body, that means this should
be possible:
    struct foo {
     struct foo x;
     int y;
   };
This one seems impossible, and even C++ fails it. Because you're directly including an actual struct within itself.
Still, my compiler is not bothered by it! It gives an overall size of 16 bytes and an offset for both x and y of 0. That embedded (incomplete) version of struct foo uses the wrong size.
A similar example in my language gives a recursion failure.
However, examples like the ones in OP are well-defined: the member involved is a single pointer of a fixed size.

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