struct type completion



I'm trying to understand how structure type completion works.

# A structure or union type of unknown
# content (as described in 6.7.2.3) is an incomplete type. It
# is completed, for all declarations of that type, by
^^^
# declaring the same structure or union tag with its defining
# content later in the same scope.
^^^^^
(6.2.5#23)

# [#3] All declarations of structure, union, or enumerated
^^^
# types that have the same scope and use the same tag declare
^^^^^^^^^^^^
# the same type. The type is incomplete100) until the
^^^^^^^^^^^^^^
# closing brace of the list defining the content, and complete
# thereafter.
(6.7.2.3#3)
(both excerpts are from n869.txt, but they're the same in the Std)

So (eg. in a file scope):

/* 1 */ struct mystruct object;
/* 2 */ struct mystruct { /*...*/ };

line 1 defines `object' (although at this point the body of `struct
mystruct' is not yet known(?)); and line 1 does not work without
line 2.

What I don't understand is, that the excerpts above seem to dictate
that line 2 fully defines the type for all instances of `struct mystruct'.
The type in line 1 must be a complete type; if it were not, then it would
not be the same type as in line 2, which seems to be required by the
second quote; and - what's obvious - we could not define `object' (we
can't define an object with incomplete type, can we?).

But then further description seems to contradict this: "... incomplete
until the closing brace ...". If the type in line 1 is complete, then
it needn't be completed, and can't of course be incomplete at the
same time.

If I add this definition:
/* test */ int test[sizeof object];
after line 1, then I get a compiler error; whereas I move it after
line 2, everything is okay. In the first case it is stunning
that I can define an object, but I can't take its size.

Could you please explain this to me? - many thanks!

--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.



Relevant Pages

  • Re: Montavista Realtime compilation failures
    ... include/linux/capability.h:47: warning: data definition has no type or ... include/linux/ipc.h:59: warning: no semicolon at end of struct or union ... include/linux/mmzone.h:307: error: dereferencing pointer to incomplete type ...
    (Linux-Kernel)
  • Re: problems building current from today
    ... I'm trying to build tinybsd as of today, ... to incomplete type 'struct freebsd7_msgctl_args' ... something not a structure or union ... *** Error code 1 ...
    (freebsd-current)
  • Re: problems building current from today
    ... I'm trying to build tinybsd as of today, ... to incomplete type 'struct freebsd7_msgctl_args' ... something not a structure or union ... *** Error code 1 ...
    (freebsd-current)
  • Re: problems building current from today
    ... I'm trying to build tinybsd as of today, ... to incomplete type 'struct freebsd7_msgctl_args' ... something not a structure or union ... *** Error code 1 ...
    (freebsd-current)