public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51352] New: g++ can't pass variable-length array as a function argument
@ 2011-11-30  8:38 jvgreen at gmail dot com
  2011-11-30  8:43 ` [Bug c++/51352] " jvgreen at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jvgreen at gmail dot com @ 2011-11-30  8:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51352
           Summary: g++ can't pass variable-length array as a function
                    argument
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jvgreen@gmail.com


According to http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html, gcc
supports variable-length arrays as an extension when compiling C++ code.  An
example is given on that page of how to pass such an array as an argument to a
function.  However, I haven't been able to get it to work.  As an example, the
simple program

  #include <iostream>
  #include <cstdlib>

  void fill_array(int dim, int array[dim][dim]);

  int main(int argc, char *const argv[]) {
    int dim = atoi(argv[1]);
    int array[dim][dim];
    fill_array(dim, array);
    for(int i = 0; i < dim; ++i) {
      for(int j = 0; j < dim; ++j) {
        std::cout << array[i][j] << "\n";
      }
    }
  }

  void fill_array(int dim, int array[dim][dim]) {
    int counter = 0;
    for(int i = 0; i < dim; ++i) {
      for(int j = 0; j < dim; ++j) {
        array[i][j] = counter++;
      }
    }
  }

won't compile under g++ version 4.6.1 (I think that's the version I was
running), despite what that page claims, instead giving errors claiming that
the parameter dim is being used outside the function.  (gcc in C99 mode can
compile the code.)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-07-27  8:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-30  8:38 [Bug c++/51352] New: g++ can't pass variable-length array as a function argument jvgreen at gmail dot com
2011-11-30  8:43 ` [Bug c++/51352] " jvgreen at gmail dot com
2011-11-30 11:03 ` redi at gcc dot gnu.org
2011-12-15  0:01 ` pinskia at gcc dot gnu.org
2014-07-12 15:39 ` paolo.carlini at oracle dot com
2014-07-12 16:00 ` paolo.carlini at oracle dot com
2021-07-27  8:39 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).