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
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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 ` jvgreen at gmail dot com
2011-11-30 11:03 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jvgreen at gmail dot com @ 2011-11-30 8:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
--- Comment #1 from Joshua Green <jvgreen at gmail dot com> 2011-11-30 06:23:40 UTC ---
(Of course, compiling under gcc requires replacing
#include <iostream>
#include <cstdlib>
with
#include <stdio.h>
#include <stdlib.h>
and
std::cout << array[i][j] << "\n";
with
printf("%d\n", array[i][j]);
but I suppose that that was implied.)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-11-30 11:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-30 09:32:23 UTC ---
This might just be a documentation bug if G++ supports declaring VLAs at block
scope but not as function arguments. No version from 4.1 onwards has supported
it
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-12-15 0:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2011-12-14
Ever Confirmed|0 |1
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-12-14 23:49:49 UTC ---
Confirmed.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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
` (2 preceding siblings ...)
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
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-12 15:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ian at rhymneyconsulting dot co.uk
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
*** Bug 61788 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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
` (3 preceding siblings ...)
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
5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-12 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
We have this comment in cp_parser_direct_declarator:
/* Normally, the array bound must be an integral constant
expression. However, as an extension, we allow VLAs
in function scopes as long as they aren't part of a
parameter declaration. */
cp_parser_error (parser,
"array bound is not an integer constant");
thus the limitation is well known (to the author of the parser at least ;)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/51352] g++ can't pass variable-length array as a function argument
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
` (4 preceding siblings ...)
2014-07-12 16:00 ` paolo.carlini at oracle dot com
@ 2021-07-27 8:39 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-27 8:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51352
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cdkrot at yandex dot ru
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 62295 has been marked as a duplicate of this bug. ***
^ 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).