public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ville.syrjala at linux dot intel.com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/112761] New: Using incomplete array types in function prototypes doesn't work Date: Wed, 29 Nov 2023 10:49:33 +0000 [thread overview] Message-ID: <bug-112761-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112761 Bug ID: 112761 Summary: Using incomplete array types in function prototypes doesn't work Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ville.syrjala at linux dot intel.com Target Milestone: --- struct foo; void func(struct foo bar[]); int main(void) { } error: array type has incomplete element type ‘struct foo’ 3 | void func(struct foo bar[]); | ^~~ This prevents using the array syntax in function prototypes with opaque types. So I have to give up either: - the array syntax, which means there is no longer any hint to the reader whether the function takes an array or a pointer to a single object - or the opaque type which is even worse since the clean abstraction is ruined (not to mention the resulting stable ABI issues). I couldn't immediately find anything in the spec that says this is illegal: - "6.7.6.2 Array declarators ... If the size is not present, the array type is an incomplete type." - "6.7.6.3 Function declarators ... If the function declarator is not part of a definition of that function, parameters may have incomplete type and may use the [*] notation in their sequences of declarator specifiers to specify variable length array types." But maybe I just don't know how to read the spec correctly? Side note: This also affects the (arguably hideous) "ptr[static 1]" syntax which would be beneficial to indicate that you can't pass in a null pointer. But I suppose that one is explicitly forbidden by the spec since we do specify a size for the "array" and thus it is not allowed to be an incomplete type.
next reply other threads:[~2023-11-29 10:49 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-29 10:49 ville.syrjala at linux dot intel.com [this message] 2023-11-29 11:10 ` [Bug c/112761] " schwab@linux-m68k.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-112761-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).