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


Groups > comp.lang.c > #390143

Re: Struct Error

From Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Struct Error
Date 2025-01-24 20:31 +0000
Organization A noiseless patient Spider
Message-ID <20250124122425.242@kylheku.com> (permalink)
References (1 earlier) <vms4km$19srg$1@dont-email.me> <vmt74h$1jac0$1@dont-email.me> <vmuaij$1qc9a$1@dont-email.me> <vmuo5o$1snhv$2@dont-email.me> <vmvjv1$259ng$1@dont-email.me>

Show all headers | View raw


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

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