help?: incomplete definition with complete definition in scope

A

Ark

Hello NG,
Consider the following snippet:
struct x_t x;
struct x_t {
int y;
};
Different compilers disagree (in "strict ANSI" mode) whether it is
legal. What is the truth (in C90 and C99 and anywhere in between)?
C99 seems to list UB case when the complete definition is not in the
same scope as declaration, but in this case it is...
Thank you,
Ark
 
C

Chris Torek

Consider the following snippet:
struct x_t x;
struct x_t {
int y;
};
Different compilers disagree (in "strict ANSI" mode) whether it is
legal. What is the truth (in C90 and C99 and anywhere in between)?

The actual text of the wording in the Standards suggests that it
is OK, but the "design" of C -- which aims for all the necessary
information to be available in a one-pass compiler, and it would
not be at that point -- suggests that it is not OK. (Hence it is
not surprising that different C compilers disagree as to whether
this code is strictly conforming.)
C99 seems to list UB case when the complete definition is not in the
same scope as declaration, but in this case it is...

This kind of question really belongs in comp.std.c, since it amounts
to argument over whether a "shall" on page 123 is more important
than some other words on page 97, etc. Here in comp.lang.c the
answer boils down to "don't do that" (because people, and compilers,
cannot agree as to whether it is OK :) ).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top