[comp.lang.c] array declaration

clark@umn-cs.CS.UMN.EDU (Robert P. Clark) (05/10/89)

There is lots of talk about why

             int a[][] = {
                          { 1, 2, 3 },
                          { 4, 5, 6 },
                          { 7, 8, 9 }, 
             };


won't compile.  My compiler barfs at this too.  But if
you change the declaration to

             static int a[][] = {
                          { 1, 2, 3 },
                          { 4, 5, 6 },
                          { 7, 8, 9 },
             };

it compiles fine.  This is what I do to get around the
problem, but I'm not exactly sure why this works and the
first doesn't.  Can anyone shed some light on this?



                     Bob Clark        clark@umn-cs.cs.umn.edu

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~                                                       ~
    ~          Never underestimate the bandwidth of         ~
    ~          a station wagon  - Andrew Tannenbaum         ~
    ~                                                       ~
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bumby@math.rutgers.edu (Richard Bumby) (05/11/89)

In article <12724@umn-cs.CS.UMN.EDU> clark@umn-cs.CS.UMN.EDU (Robert
P. Clark) writes:

> There is lots of talk about why
> 
>              int a[][] = {
>                           <data omitted>
>              };
> 
> 
> won't compile.  My compiler barfs at this too.  But if
> you change the declaration to
> 
>              static int a[][] = {
>                           <data omitted>
>              };
> 
> it compiles fine.  This is what I do to get around the
> problem, but I'm not exactly sure why this works and the
> first doesn't.  Can anyone shed some light on this?
> 
> ... <signature deleted>...

My guess is that your (unidentified) compiler is just providing an
extension of the type suggested by the original poster in a context
where it would be reasonably safe.  I used the first edition of K & R
as a reference, but have done no experiments with the various C
environments that I have access to (I guess I am still just a pure
mathematician).  I found that section 5.7 was sufficiently clear about
declaration and use of multidimensional arrays, and section 8.4 of the
reference manual (appendix A) about the limitation of "arrays of
unknown size" that I never pursued the matter further.
--
-- 

--R. T. Bumby ** Math ** Rutgers ** New Brunswick **
(in one form or another for all kinds of mail)
[bumby@math.rutgers.edu]