Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to understand this?

38 views
Skip to first unread message
Message has been deleted

James Kuyper

unread,
Apr 10, 2013, 10:14:08 AM4/10/13
to
On 04/10/2013 09:49 AM, sts...@gmail.com wrote:
> C11 states that "A specific type shall have its content defined at most once"(6.7.2.3)
> what its meaning is the same tag cannot be declare more than once?

No, the following does not violate 6.7.2.3:

struct forward;
struct forward
{
char completed;
double definition;
};

That's because only the second declaration of struct forward defines the
content. The first declaration merely establishes that it is a struct.
That's all that you need in any context which does not require that the
struct be a complete type - this fact can be used to create what are
called "opaque types" - types whose details are not known to the code
that uses them.

> otherwise, how comes "A struct/union/enum cannot be define more than once"?

It's a principle of good software engineering to only define things
once; if you define something more than once, the two definitions can
get out of sync, and that can lead to uncertainties about which
definition is correct. This rule serves primarily to enforce that principle.

> in addition,
> is
> {
> //...
> struct a
> {
> //
> }
> //...
> struct a
> {
> //
> }
> } legal?

As written, that code contains two syntax errors because there's no ';'
after the struct definitions, and two more because neither struct
definition specifies any members for the struct. I assume that you're
not talking about those issues.

Assuming you fixed those two issues, that's precisely the kind of code
6.7.2.3p1 is intended to prohibit.

Note: 6.7.2.3p1 does not apply to type definitions in different
translation units. That's because such definitions are considered to
define different types (6.7.2.3p5). They're compatible types (6.2.7p1),
which is all that you need to use them in interfaces between the two
translation units, but they are not the same type.

0 new messages