public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* g++ allows variable array creation
@ 2004-01-19 11:31 Omar Shaikh
2004-01-19 12:12 ` Andrew Pinski
0 siblings, 1 reply; 3+ messages in thread
From: Omar Shaikh @ 2004-01-19 11:31 UTC (permalink / raw)
To: gcc-bugs
Dear All
I found something in the GNU compiler that I am not
sure is a bug or the latest change to the C++
standard. However, the same did not work in Microsoft
C++ (v. 13.10.3077), the C++ compiler that comes with
Microsoft .NET product. I ran this code on both Win32
and Linux platforms with full warnings on (-Wall).
Surprisingly, there were no warnings either.
The compiler that I used on Windows (XP):
MinGW: c++ (GCC) 3.2.3 (mingw special 20030504-1)
Compiler used on (Mandrake) Linux:
g++ (GCC) 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)
#include <iostream.h>
class A
{
int v;
public:
A () { }
void SetV (int nv) { v = nv; }
int GetV () { return v; }
};
int main ()
{
A x;
int i;
cout << "Enter array size: "; cin >> i;
x.SetV(i);
const int m = x.GetV();
int arr[m]; // Works fine!
cout << "Array size = " << sizeof(arr) << " bytes" <<
endl;
return 0;
}
Here are two sample runs of the program. (Underscored
text is user i/p.)
Enter array size: _10_
Array size = 40 bytes
Next run
Enter array size: _25_
Array size = 100 bytes
The code above works fine, though the array size can
be decided during runtime. Please let me know if I am
missing something.
Thank you.
Omar
__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ allows variable array creation
2004-01-19 11:31 g++ allows variable array creation Omar Shaikh
@ 2004-01-19 12:12 ` Andrew Pinski
2004-01-19 16:42 ` Gabriel Dos Reis
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2004-01-19 12:12 UTC (permalink / raw)
To: Omar Shaikh; +Cc: gcc-bugs, Andrew Pinski
On Jan 19, 2004, at 03:31, Omar Shaikh wrote:
> Dear All
>
> I found something in the GNU compiler that I am not
> sure is a bug or the latest change to the C++
> standard. However, the same did not work in Microsoft
> C++ (v. 13.10.3077), the C++ compiler that comes with
> Microsoft .NET product. I ran this code on both Win32
> and Linux platforms with full warnings on (-Wall).
> Surprisingly, there were no warnings either.
That is because VLA is part of GNU C, C99, and GNU C++ and will most
likely part of a future
C++ standard (if not already part of a draft). To get a warning from
GCC use -pedantic.
Thanks,
Andrew Pinski
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: g++ allows variable array creation
2004-01-19 12:12 ` Andrew Pinski
@ 2004-01-19 16:42 ` Gabriel Dos Reis
0 siblings, 0 replies; 3+ messages in thread
From: Gabriel Dos Reis @ 2004-01-19 16:42 UTC (permalink / raw)
To: Andrew Pinski; +Cc: Omar Shaikh, gcc-bugs
Andrew Pinski <pinskia@physics.uc.edu> writes:
| On Jan 19, 2004, at 03:31, Omar Shaikh wrote:
|
| > Dear All
| >
| > I found something in the GNU compiler that I am not
| > sure is a bug or the latest change to the C++
| > standard. However, the same did not work in Microsoft
| > C++ (v. 13.10.3077), the C++ compiler that comes with
| > Microsoft .NET product. I ran this code on both Win32
| > and Linux platforms with full warnings on (-Wall).
| > Surprisingly, there were no warnings either.
|
|
| That is because VLA is part of GNU C, C99, and GNU C++ and will most
| likely part of a future
| C++ standard (if not already part of a draft). To get a warning from
| GCC use -pedantic.
VLA is part of no C++ standard draft I know of. Variably modified
types come with their hosts of problems. How they should interact
with the C++ type system, especially templates, is yet not determined.
And I have seen no proposal to enlighten that point.
IMHO, it is unlikely that such beasts would be made part of C++ if they
can't play with templates .
And of course, we do have PRs about VLAs in C++ (either with classes
or templates) :-)
-- Gaby
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-01-19 16:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-19 11:31 g++ allows variable array creation Omar Shaikh
2004-01-19 12:12 ` Andrew Pinski
2004-01-19 16:42 ` Gabriel Dos Reis
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).