Re: Arrays of incomplete type
- From: Eric Sosman <Eric.Sosman@xxxxxxx>
- Date: Tue, 28 Feb 2006 17:06:11 -0500
ena8t8si@xxxxxxxxx wrote On 02/28/06 11:42,:
Eric Sosman wrote:
ena8t8si@xxxxxxxxx wrote On 02/28/06 06:55,:
Eric Sosman wrote:
Konrad Schwarz wrote On 02/27/06 12:22,:
struct opaque default_value [];
Don't you need an `extern' here? Even if `struct opaque'
were a complete type, this declaration would be incorrect as
it stands.
Really? What leads you to conclude that
struct opaque { int x; };
struct opaque default_value [];
is an error?
Try it without the first line. By declaring the
members of `struct opaque' you've made it into an
object type rather than an incomplete type.
I knew that. Your comment said it would be incorrect
even if struct opaque were a complete type. That's the
case I was asking about.
Sorry; I mistook what you were asking about. It was
my belief that the empty brackets declared an incomplete
array type (6.7.5.2/4, 6.2.5/22), so the questionable line
constituted an attempt to define an object (the array) of
incomplete type. Since an object definition must reserve
storage for the object (6.7/5) and since the size of an
incomplete type is unknown (6.2.5/1), I believed the line
had to be incorrect, roughly equivalent to `void x;'.
... but researching all those section numbers to gather
iron-clad confirmation of my belief has served only to
confuse me. In particular, I ran across 6.9.2/2:
"A declaration of an identifier for an object that
has file scope without an initializer, and without a
storage-class specifier [...], constitutes a tentative
definition. If a translation unit contains one or more
tentative definitions for an identifier [and no external
definition], then the behavior is exactly as if the
translation unit contains a file scope declaration [...]
with an initializer equal to 0."
So: The troublesome pair of lines might be equivalent to
struct opaque { int x; };
struct opaque default_value[] = { 0 };
This would be valid, because the initializer completes the
type of the array by providing its size (6.7.8/22). However,
this latter section speaks of "an explicit initializer," so
it's not clear to me whether the implied "initializer equal
to 0" of 6.9.2/2 is sufficient to determine the size and
make the array type complete.
It's unclear to me which section prevails (or whether
there's a subtle angels-on-pinheads argument that shows
they're not in conflict). I think I'll just throw myself
on the mercy of the Court.
--
Eric.Sosman@xxxxxxx
.
- References:
- Arrays of incomplete type
- From: Konrad Schwarz
- Re: Arrays of incomplete type
- From: Eric Sosman
- Re: Arrays of incomplete type
- From: Konrad Schwarz
- Re: Arrays of incomplete type
- From: Eric Sosman
- Re: Arrays of incomplete type
- From: Eric Sosman
- Arrays of incomplete type
- Prev by Date: Re: Arrays of incomplete type
- Previous by thread: Re: Arrays of incomplete type
- Next by thread: Re: Arrays of incomplete type
- Index(es):
Relevant Pages
|