If this is (as I am fairly sure) a bug, then it will
surely be a bug in the C front end, and as such be
architecture-independent.

The behaviour here complained of is peculiar to -pedantic,
which chucks an error for what I believe is correct code.
It's not even a warning otherwise, and I think rightly.
The behaviour is seen in gcc-4.0.2 and gcc-4.1, an
may well be older, as I have only recently started to use
-pedantic by default.

BS ISO/IEC 9899:1999 6.2.5 para.22 (first two sentences)
An array type of unknown size is an incomplete type.  It is completed, for an
identifier of
that type, by specifying the size in a later declaration (with internal or
external linkage).

There's a great deal of murk in the Standard, some of which is relevant, but
in this cases at least, m'lud, the law is clear.  Just as one may have

extern int thingy1[];
extern int thingy1[1];

one may have (with file scope, not block scope)

static int thingy2[];
static int thingy2[1];

gcc is happy with the 'extern' version, but not with the 'static' ones:
it gags, claiming that the first declaration is bad ("array size missing")
and the second is inconsistent with it ("conflicting types").
Perhaps the much stricter rules for block-scope declarations confused
the implementers?  Specifically, objects other than function parameters
declared in a block which are not explicitly given the storage-class
'extern' have no linkage  (Standard 6.2.2 para. 6), and an object with
no linkage may not have an incomplete type declaration (6.7 para. 7).
The reason for this restriction escapes me (why on earth not allow
deferred type completion here too?).

This is not the end of the story, but I'm steering clear of the
full horrors of 'extern' in this particular bug report.

I have not found a comparable problem with other incomplete types
(pointers to incompletely defined struct types, &c.), irrespective
of linkage.

Bernard Leak
--
What's wrong with a recursive dmalloc, anyway?


-- 
           Summary: incomplete (unsized) static array types cannot be
                    completed
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bernard at brenda-arkle dot demon dot co dot uk
 GCC build triplet: (same)
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: (same)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26581

Reply via email to