Re: Arrays of incomplete type





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

.



Relevant Pages

  • Re: Arrays of incomplete type
    ... Don't you need an `extern' here? ... Even if `struct opaque' ... this declaration would be incorrect as ... Your comment said it would be incorrect ...
    (comp.std.c)
  • Re: Arrays of incomplete type
    ... Even if `struct opaque' ... this declaration would be incorrect as ... What leads you to conclude that ...
    (comp.std.c)
  • Re: Mozilla Firefox problem Please Hejp
    ... Error Line 1 column 0: no document type declaration; ... number of incorrect error messages. ... (Remember XHTML is all lower-case) and/or check that they ...
    (microsoft.public.publisher)
  • Re: anonymous initializer problem
    ... the declaration section (via initializer). ... and has only one public constructor that takes an array of field objects. ... This way I could define my dictionary in the declaration section where it is ... costructor declare custom static arrays that use the dictionary values, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is the order of static block execution guaranteed ?
    ... >>even though they're declared in the same line of source code. ... The declaration and initialization are after the assignment in the ... there is a static initializer and after it ... a class variable declaration combined with a class variable initializer. ...
    (comp.lang.java.programmer)