Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #390177

Re: Struct Error

From Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Struct Error
Date 2025-01-27 04:05 +0000
Organization A noiseless patient Spider
Message-ID <20250126193003.409@kylheku.com> (permalink)
References <vmr5gg$137jo$1@dont-email.me> <vms4km$19srg$1@dont-email.me> <vmt74h$1jac0$1@dont-email.me> <20250124163740.00006281@yahoo.com> <vn61ho$1pf2$1@dont-email.me>

Show all headers | View raw


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.

Sure, something in a type not being specified is not a problem until the
information is actually needed for something. We can think about
a lazy type evaluation system. Functional programming languages
tend to have them.

But note that the rule /is/ actually consistent among aggregates.
Both an array and struct are aggregates. The elements are to
an array roughly the same thing that members are to a struct.
A struct may not have members of incomplete type,
An array may not have elements of incomplete type.

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.

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;
  };

That cannot be the reason why the pointer to array works in GNU C++.

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

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Struct Error bart <bc@freeuk.com> - 2025-01-22 16:14 +0000
  Re: Struct Error Kaz Kylheku <643-408-1753@kylheku.com> - 2025-01-22 20:05 +0000
    Re: Struct Error Ben Bacarisse <ben@bsb.me.uk> - 2025-01-22 21:00 +0000
  Re: Struct Error Richard Harnden <richard.nospam@gmail.invalid> - 2025-01-22 20:08 +0000
  Re: Struct Error Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-01-22 22:27 +0000
  Re: Struct Error James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-01-22 20:05 -0500
    Re: Struct Error learningcpp1@gmail.com (m137) - 2025-01-23 03:49 +0000
      Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-22 23:15 -0800
      Re: Struct Error James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-01-23 03:37 -0500
    Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-22 23:31 -0800
    Re: Struct Error bart <bc@freeuk.com> - 2025-01-23 10:54 +0000
      Re: Struct Error BGB <cr88192@gmail.com> - 2025-01-23 14:58 -0600
        Re: Struct Error bart <bc@freeuk.com> - 2025-01-24 00:51 +0000
          Re: Struct Error BGB <cr88192@gmail.com> - 2025-01-24 00:27 -0600
          Re: Struct Error David Brown <david.brown@hesbynett.no> - 2025-01-24 09:45 +0100
            Re: Struct Error Kaz Kylheku <643-408-1753@kylheku.com> - 2025-01-24 20:31 +0000
              Re: Struct Error bart <bc@freeuk.com> - 2025-01-24 22:53 +0000
              Re: Struct Error James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-01-24 20:53 -0500
          Re: Struct Error James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-01-24 08:43 -0500
            Re: Struct Error bart <bc@freeuk.com> - 2025-01-24 23:32 +0000
      Re: Struct Error Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-01-23 23:50 +0000
        Re: Struct Error bart <bc@freeuk.com> - 2025-01-24 00:37 +0000
          Re: Struct Error Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-01-24 00:57 +0000
            Re: Struct Error Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-01-23 17:23 -0800
            Re: Struct Error bart <bc@freeuk.com> - 2025-01-24 01:27 +0000
      Re: Struct Error James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-01-24 08:24 -0500
      Re: Struct Error Michael S <already5chosen@yahoo.com> - 2025-01-24 16:37 +0200
        Re: Struct Error bart <bc@freeuk.com> - 2025-01-26 19:14 +0000
          Re: Struct Error Michael S <already5chosen@yahoo.com> - 2025-01-26 23:14 +0200
          Re: Struct Error Kaz Kylheku <643-408-1753@kylheku.com> - 2025-01-27 04:05 +0000
            Re: Struct Error bart <bc@freeuk.com> - 2025-01-27 20:19 +0000
          Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-29 02:59 -0800
            Re: Struct Error bart <bc@freeuk.com> - 2025-01-29 11:36 +0000
              Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-30 11:51 -0800
            Re: Struct Error Richard Damon <richard@damon-family.org> - 2025-01-29 07:32 -0500
              Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-29 07:52 -0800
  Re: Struct Error Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-01-22 23:11 -0800
  Re: Struct Error Andrey Tarasevich <noone@noone.net> - 2025-02-02 20:35 -0800

csiph-web