Thread: Re: [Dev-C++] Ansi compatible?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-04-18 09:59:14
|
Ummm not sure, I don't think you need iostream. But if so, try
#include <iostream>
then inside main()
using namespace std;
>From: "Anon" <an...@pu...>
>To: <dev...@li...>
>Subject: [Dev-C++] Ansi compatible?
>Date: Thu, 18 Apr 2002 11:50:11 +0530
>
>Hey!
>Can anyone please tell me if the following code is ANSI compatible? It
>compiles fine with DevC++ but throws up an error in Borland 5.0
>
>#include <iostream.h>
>#include <stdlib.h>
>
>int main()
>{
> int i=10;
> int arr[i]; //can it do accept Integer variable
> system("PAUSE");
> return 0;
>}
>
>My classmates say that this is a violation of ANSI standard.
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
|
|
From: <lho...@ho...> - 2002-04-18 13:02:42
|
I think that is ANSI compatible but the BCB does not support.
try this:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc,char **argv){
const int i=10;
//use a const here.
int arr[i];
system("pause");
return 0;
}
I havn't BCB,but I hava tested it with CL.exe.
>From: "Anon" <an...@pu...>
>To: <dev...@li...>
>Subject: [Dev-C++] Ansi compatible?
>Date: Thu, 18 Apr 2002 11:50:11 +0530
>
>Hey!
>Can anyone please tell me if the following code is ANSI compatible? It
compiles fine with DevC++ but throws up an error in Borland 5.0
>
>#include <iostream.h>
>#include <stdlib.h>
>
>int main()
>{
> int i=10;
> int arr[i]; //can it do accept Integer variable
> system("PAUSE");
> return 0;
>}
>
>My classmates say that this is a violation of ANSI standard.
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:
http://messenger.microsoft.com/cn
|
|
From: <lho...@ho...> - 2002-04-18 13:03:28
|
I think that is ANSI compatible but the BCB does not support.
try this:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc,char **argv){
const int i=10;
//use a const here.
int arr[i];
system("pause");
return 0;
}
I havn't BCB,but I test it with CL.exe.
>From: "Anon" <an...@pu...>
>To: <dev...@li...>
>Subject: [Dev-C++] Ansi compatible?
>Date: Thu, 18 Apr 2002 11:50:11 +0530
>
>Hey!
>Can anyone please tell me if the following code is ANSI compatible? It
compiles fine with DevC++ but throws up an error in Borland 5.0
>
>#include <iostream.h>
>#include <stdlib.h>
>
>int main()
>{
> int i=10;
> int arr[i]; //can it do accept Integer variable
> system("PAUSE");
> return 0;
>}
>
>My classmates say that this is a violation of ANSI standard.
>
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger:
http://messenger.microsoft.com/cn
|
|
From: <jar...@ig...> - 2002-04-18 10:56:44
|
>>From: "Anon" <an...@pu...>
>>To: <dev...@li...>
>>Subject: [Dev-C++] Ansi compatible?
>>Date: Thu, 18 Apr 2002 11:50:11 +0530
>>
>>Hey!
>>Can anyone please tell me if the following code is ANSI compatible? It
>>compiles fine with DevC++ but throws up an error in Borland 5.0
>>
>>#include <iostream.h>
this should be #include <iostream> but you don;t need it in this
program
>>#include <stdlib.h>
this should be
#include <cstdlib>
using std::system; // since you need the system function from cstdlib
>>
>>int main()
>>{
>> int i=10;
>> int arr[i]; //can it do accept Integer variable
NO, according to the standard this is only possible if you
replace the line above by
const int i=10;
>> system("PAUSE");
>> return 0;
>>}
>>
>>My classmates say that this is a violation of ANSI standard.
They're right.
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
|
|
From: David M. <ci...@ya...> - 2002-04-19 13:24:27
|
An array is not dynamic, the value you pass it at
initalization must be a constat of some sort.
if 'i' were to change during the program some weird
voodoo (the program will crash,the world will end,etc.)
all this will hapen because it cannot change the size of an
array at runtime(reason no. 1 linked lists were created)
> >From: "Anon" <an...@pu...>
> >To: <dev...@li...>
> >Subject: [Dev-C++] Ansi compatible?
> >Date: Thu, 18 Apr 2002 11:50:11 +0530
> >
> >Hey!
> >Can anyone please tell me if the following code is ANSI
> compatible? It
> >compiles fine with DevC++ but throws up an error in Borland 5.0
> >
> >#include <iostream.h>
> >#include <stdlib.h>
> >
> >int main()
> >{
> > int i=10;
> > int arr[i]; //can it do accept Integer variable
> > system("PAUSE");
> > return 0;
> >}
> >
> >My classmates say that this is a violation of ANSI standard.
> >
> >
> >---
> >Outgoing mail is certified Virus Free.
> >Checked by AVG anti-virus system (http://www.grisoft.com).
> >Version: 6.0.346 / Virus Database: 194 - Release Date: 4/10/2002
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger:
> http://messenger.msn.com
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
|
|
From: Bob W. <bo...@ph...> - 2002-04-19 21:57:34
|
David,
An array is not dynamic, the value you pass it at initalization must =
be a constat of some sort.if 'i' were to change during the program some =
weird voodoo (the program will crash,the world will end,etc.) all this =
will hapen because it cannot change the size of an array at =
runtime(reason no. 1 linked lists were created)
I am in the process of learning C++, as Ioannis well knows, and a week =
or so ago I was working on the array chapter. In the past I have done =
most of my programming in pascal, and every pascal compiler I have used =
will not compile an array if the size of the array is a variable, i.e., =
no dynamic arrays. Just fooling around I modified the simple little C++ =
array program to define an array with a variable. I had not done any =
research but was confident that the compiler would flag an error and =
bail out.=20
Not So! the program compiled and ran allowing me to change the size of =
the array. I tested the bounds of the program and could build quite =
large arrays. the size_of function always returnd the correct size of =
the array. I was really surprised because that it worked. I have not =
employed the technique in any real world program, because I felt that it =
would be much safer with pointers and linked lists.=20
Your message above confirmed what I suspected but had not taken the time =
to investigate. Stroustrup says:
The number of elements of the array, the array bound, must be a =
constant expresseion (=A7C.5)
Paragraph C.5 says in part:
A constant expression evaluates to an integral of enumeration =
constant. Such an expression is composed of literals, enumerators, and =
const initialized by constant expressions. < . . . > Intuitively, =
constant expressions are simple expressions that can be evaluated by the =
compiler before the program is linked and starts to run.
That tells me that the compiler should have caught this and bailed out =
rather than compiling, linking, and running this program:=20
#include <iostream.h>
#include <stdlib.h>
int main
{
int arraySize =3D 1;
std::cout << "Enter the size of the array: ";
std::cin >> arraySize;
if (!(arraySize > 0))
{
system("pause");
return 0;
}
int myArray[arraySize];
int arrayLength =3D sizeof(myArray)/sizeof(myArray[0]);
for (int i=3D0; i < arrayLength; i++) // 0 to arrayLength-1
{
myArray[i] =3D (i + 1) * 2 + 1;
}
for (int i=3D0; i< arrayLength; i++) // 0 to arrayLength-1
{
std::cout << i << ": " << myArray[i] << "\n";
}
=20
system("pause");
return 0;
}
The faulty compiler is the one used by Bloodshed. Visual C++ 6.0 caught =
the error. That is the second and most serious problem I have found with =
the compiler used by the dev-c++ environment. It appears it will =
properly compile ANSI standard code, but it will also compile code that =
is clearly outside of the standard.=20
I believe that the dev-c++ compiler is the mingw compiler.=20
Regards,
Bob Wilson
|
|
From: Jason H. <jas...@bt...> - 2002-04-20 00:11:36
|
Something people using Dev-C++ may not realise is that the supplied = compiler is MinGW and that it is a port of the GCC compilers as used on = linux and many other unix based OS's. The version of GCC that MinGW = supplies is 2.?? (I can't remember the exact number) which is fairly old = now, as the current linux version of GCC is 3.??. The current MinGW version is not 100% standards compliant because of = this, and I believe also that the developers of GCC made several = additions to it for use within Linux (or Unix?). I don't know all the = details, so maybe someone with a bit more knowledge can fill in the = gaps, but it is well worth considering if you are on the hunt for = perfect ANSI compliant C++. Another point is that the developers of Dev-C++ and the developers MinGW = cannot be responsible when the compiler doesn't work in exactly the way = you expect. On the brightside, you are getting a free, open-source, = cross-platform and non-proprietory compiler. The source for the latest GCC versions is freely available, but AFAIK no = one has yet managed to produce a successful port of it to the windows = environment. You are welcome to try. Jason. |
|
From: Ioannis V. <no...@ho...> - 2002-04-20 17:29:25
|
<http://run.to/noicys> -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Jason Hardman Sent: Saturday, April 20, 2002 1:36 AM To: Dev-C++ Subject: Re: [Dev-C++] Dev-C++ Users Beware! Something people using Dev-C++ may not realise is that the supplied compiler is MinGW and that it is a port of the GCC compilers as used on linux and many other unix based OS's. The version of GCC that MinGW supplies is 2.?? (I can't remember the exact number) which is fairly old now, as the current linux version of GCC is 3.??. GCC 3.x is fairly new. In fact Suse Linux 7.3 that i have uses GCC 2.x as the default compiler. The latest version of MINGW is pretty good. The current MinGW version is not 100% standards compliant because of this, Noone is yet. In fact MINGW is one of the most compliant compilers i have ever seen, more compliant than Visual C++ 7 .NET for example. and I believe also that the developers of GCC made several additions to it for use within Linux (or Unix?). Yes, but the MINGW team has added Win32 API support. I don't know all the details, so maybe someone with a bit more knowledge can fill in the gaps, but it is well worth considering if you are on the hunt for perfect ANSI compliant C++. Yes we all are. Another point is that the developers of Dev-C++ and the developers MinGW cannot be responsible when the compiler doesn't work in exactly the way you expect. I did not understand what you mean by that. On the brightside, you are getting a free, open-source, cross-platform and non-proprietory compiler. The source for the latest GCC versions is freely available, but AFAIK no one has yet managed to produce a successful port of it to the windows environment. You are welcome to try. As far as i know MING 3.x is currently being made. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys |
|
From: Jason H. <jas...@bt...> - 2002-04-20 17:56:47
|
Message
----- Original Message -----=20
From: Ioannis Vranos=20
To: Dev-C++=20
Sent: Saturday, April 20, 2002 6:28 PM
Subject: RE: [Dev-C++] Dev-C++ Users Beware!
Another point is that the developers of Dev-C++ and the developers =
MinGW cannot be responsible when the compiler doesn't work in exactly =
the way you expect. =20
I did not understand what you mean by that.
I have noticed that people in the past have posted what they believe to =
be issues with the compiler here in the expectation that the Dev-C++ =
community can fix compiler bugs. I decided that some people don't quite =
understand the relationship between IDE and compiler. What I was trying =
to say in a way was that if the problem is one of ANSI compliance in the =
compiler then the people responsible for that end of the system are the =
developers of GCC. Admittedly there can be occasions where the source of =
a problem is Dev-C++ or MinGW.
When I find a problem I try to narrow it down as much as possible, or =
even locate the source of it, before talking to anyone about it.
Jason.
|
|
From: Abhijit S. <mu...@gm...> - 2002-04-20 10:43:03
|
Quote Microsoft: "This isn't a bug, it's a feature." Seriously, though, = this is one feature of the GCC compiler (I remember reading about it in = the DJGPP docs). If you're still looking for the compiler to stop when = it encounters non-ANSI code, there must be a command-line options = somewhere. Yup, here it is... from the Dev-C++ help file. -------------------------------------------------------------------------= ------- - Support all ANSI C standard programs (compiler parameter : -ansi): This turns off certain features of GNU C that are incompatible with ANSI = C, such as the asm, inline and typeof keywords, and predefined macros = such as unix and vax that identify the type of system you are using. It = also enables the undesirable and rarely used ANSI trigraph feature, and = it disables recognition of C++ style // comments. -------------------------------------------------------------------------= ------- But what the hell, GCC is kind of a standard in itself. mdeth O m.o.t.o[P.S.Y.C.H.O]=20 http://mudeth.tripod.com | ibr...@bi... | mu...@gm... ----- Original Message -----=20 From: Bob Wilson=20 To: Dev-C++ User Mailing List=20 Sent: Saturday, April 20, 2002 3:29 AM Subject: [Dev-C++] Dev-C++ Users Beware! David, An array is not dynamic, the value you pass it at initalization must = be a constat of some sort.if 'i' were to change during the program some = weird voodoo (the program will crash,the world will end,etc.) all this = will hapen because it cannot change the size of an array at = runtime(reason no. 1 linked lists were created) I am in the process of learning C++, as Ioannis well knows, and a week = or so ago I was working on the array chapter. In the past I have done = most of my programming in pascal, and every pascal compiler I have used = will not compile an array if the size of the array is a variable, i.e., = no dynamic arrays. Just fooling around I modified the simple little C++ = array program to define an array with a variable. I had not done any = research but was confident that the compiler would flag an error and = bail out.=20 Not So! the program compiled and ran allowing me to change the size of = the array. I tested the bounds of the program and could build quite = large arrays. the size_of function always returnd the correct size of = the array. I was really surprised because that it worked. I have not = employed the technique in any real world program, because I felt that it = would be much safer with pointers and linked lists.=20 Your message above confirmed what I suspected but had not taken the = time to investigate. Stroustrup says: The number of elements of the array, the array bound, must be a = constant expresseion (=A7C.5) Paragraph C.5 says in part: A constant expression evaluates to an integral of enumeration = constant. Such an expression is composed of literals, enumerators, and = const initialized by constant expressions. < . . . > Intuitively, = constant expressions are simple expressions that can be evaluated by the = compiler before the program is linked and starts to run. That tells me that the compiler should have caught this and bailed out = rather than compiling, linking, and running this program:=20 #include <iostream.h> #include <stdlib.h> int main { int arraySize =3D 1; std::cout << "Enter the size of the array: "; std::cin >> arraySize; if (!(arraySize > 0)) { system("pause"); return 0; } int myArray[arraySize]; int arrayLength =3D sizeof(myArray)/sizeof(myArray[0]); for (int i=3D0; i < arrayLength; i++) // 0 to arrayLength-1 { myArray[i] =3D (i + 1) * 2 + 1; } for (int i=3D0; i< arrayLength; i++) // 0 to arrayLength-1 { std::cout << i << ": " << myArray[i] << "\n"; } =20 system("pause"); return 0; } The faulty compiler is the one used by Bloodshed. Visual C++ 6.0 = caught the error. That is the second and most serious problem I have = found with the compiler used by the dev-c++ environment. It appears it = will properly compile ANSI standard code, but it will also compile code = that is clearly outside of the standard.=20 I believe that the dev-c++ compiler is the mingw compiler.=20 Regards, Bob Wilson |
|
From: Andres R. <lo...@ho...> - 2002-04-20 13:02:13
|
Yes. Variable sized arrays are GNUC extension. If you use =96ansi or =96pedantic switches on commandline, you get only warning: =20 test.cpp: In function `int main()': test.cpp:12: warning: ANSI C++ forbids variable-size array `myArray' =20 Andres =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Abhijit Shylanath Sent: Saturday, April 20, 2002 1:21 PM To: Dev-C++ User Mailing List Subject: Re: [Dev-C++] Dev-C++ Users Beware! =20 Quote Microsoft: "This isn't a bug, it's a feature." Seriously, though, this is one feature of the GCC compiler (I remember reading about it in the DJGPP docs). If you're still looking for the compiler to stop when it encounters non-ANSI code, there must be a command-line options somewhere. Yup, here it is... from the Dev-C++ help file. _____ =20 - Support all ANSI C standard programs (compiler parameter : -ansi): =20 This turns off certain features of GNU C that are incompatible with ANSI C, such as the asm, inline and typeof keywords, and predefined macros such as unix and vax that identify the type of system you are using. It also enables the undesirable and rarely used ANSI trigraph feature, and it disables recognition of C++ style // comments. _____ =20 But what the hell, GCC is kind of a standard in itself. mdeth * m.o.t.o[P.S.Y.C.H.O]=20 http://mudeth.tripod.com | ibr...@bi... | mu...@gm... ----- Original Message -----=20 From: Bob Wilson <mailto:bo...@ph...> =20 To: Dev-C++ User Mailing List <mailto:dev...@li...> =20 Sent: Saturday, April 20, 2002 3:29 AM Subject: [Dev-C++] Dev-C++ Users Beware! =20 David, An array is not dynamic, the value you pass it at initalization must be a constat of some sort.if 'i' were to change during the program some weird voodoo (the program will crash,the world will end,etc.) all this will hapen because it cannot change the size of an array at runtime(reason no. 1 linked lists were created) I am in the process of learning C++, as Ioannis well knows, and a week or so ago I was working on the array chapter. In the past I have done most of my programming in pascal, and every pascal compiler I have used will not compile an array if the size of the array is a variable, i.e., no dynamic arrays. Just fooling around I modified the simple little C++ array program to define an array with a variable. I had not done any research but was confident that the compiler would flag an error and bail out.=20 =20 Not So! the program compiled and ran allowing me to change the size of the array. I tested the bounds of the program and could build quite large arrays. the size_of function always returnd the correct size of the array. I was really surprised because that it worked. I have not employed the technique in any real world program, because I felt that it would be much safer with pointers and linked lists.=20 =20 Your message above confirmed what I suspected but had not taken the time to investigate. Stroustrup says: The number of elements of the array, the array bound, must be a constant expresseion (=A7C.5) Paragraph C.5 says in part: A constant expression evaluates to an integral of enumeration constant. Such an expression is composed of literals, enumerators, and const initialized by constant expressions. < . . . > Intuitively, constant expressions are simple expressions that can be evaluated by the compiler before the program is linked and starts to run. That tells me that the compiler should have caught this and bailed out rather than compiling, linking, and running this program:=20 =20 #include <iostream.h> #include <stdlib.h> =20 int main { int arraySize =3D 1; std::cout << "Enter the size of the array: "; std::cin >> arraySize; if (!(arraySize > 0)) { system("pause"); return 0; } int myArray[arraySize]; int arrayLength =3D sizeof(myArray)/sizeof(myArray[0]); for (int i=3D0; i < arrayLength; i++) // 0 to arrayLength-1 { myArray[i] =3D (i + 1) * 2 + 1; } for (int i=3D0; i< arrayLength; i++) // 0 to arrayLength-1 { std::cout << i << ": " << myArray[i] << "\n"; } =20 system("pause"); return 0; } The faulty compiler is the one used by Bloodshed. Visual C++ 6.0 caught the error. That is the second and most serious problem I have found with the compiler used by the dev-c++ environment. It appears it will properly compile ANSI standard code, but it will also compile code that is clearly outside of the standard.=20 =20 I believe that the dev-c++ compiler is the mingw compiler.=20 =20 Regards, =20 Bob Wilson =20 |
|
From: Bob W. <bo...@ph...> - 2002-04-20 16:10:47
|
Andres, If it is GNUC extension, that greatly relieves my concern, however none = of the compiler switches you mention generate any warnings. I tried them = individually and in combination in both the compiler options and the = project options. It is possible that the Bloodshed IDE is not passing = the switches properly to the compiler, but I doubt it.=20 Regards, Bob -Yes. Variable sized arrays are GNUC extension. If you use =96ansi or =96pedantic switches on commandline, you get = only warning: =20 test.cpp: In function `int main()': test.cpp:12: warning: ANSI C++ forbids variable-size array `myArray' |
|
From: Andres R. <lo...@ho...> - 2002-04-20 17:40:39
|
Hello! =20 You are right. =96ansi does not generate any warnings. I useed it with =96pedantic option. I used MSYS and MinGW (latest, see below) >gcc -v gcc version 2.95.3-6 (mingw special) =20 I noticed that MinGW that ships with Dev-C++ 4.0(1) is slightly older. >gcc =96v gcc version 2.95.2 19991024 (release) =20 I tried it with Dev-C++ 4.1 and =84original=93 compiler. I got worning I mentioned. I tried it on command line and it =84worked=93 fine also. =20 Try playing around if you really want to see a little warning message ;) =20 Andres. =20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Bob Wilson Sent: Saturday, April 20, 2002 7:12 PM To: Dev-C++ User Mailing List Subject: Re: [Dev-C++] Dev-C++ Users Beware! =20 Andres, =20 If it is GNUC extension, that greatly relieves my concern, however none of the compiler switches you mention generate any warnings. I tried them individually and in combination in both the compiler options and the project options. It is possible that the Bloodshed IDE is not passing the switches properly to the compiler, but I doubt it.=20 =20 Regards, =20 Bob -Yes. Variable sized arrays are GNUC extension. =20 If you use =96ansi or =96pedantic switches on commandline, you get only warning: =20 test.cpp: In function `int main()': test.cpp:12: warning: ANSI C++ forbids variable-size array `myArray' =20 |
|
From: Andres R. <lo...@ho...> - 2002-04-20 21:55:01
|
Hello again! =20 Only one note more.. (I hope this would be the last..) If you really want to get error, not warning, use =96pedantic-error parameter. You can really get an error from that. =20 On MinGW-users list I got inf, that Windows allows allocating stack space in 2 MB chunks maximum. I tested it and it is really true. Maximum variable sized array you can get is around 2M Bait. =20 Andres. |
|
From: Luigi S. <gi...@li...> - 2002-04-22 03:58:58
Attachments:
gcc_68.zip
|
Hello all, looking at some HTML files related to gcc 2.8.1 (I can't remember where I got them), I found the file attached to this mail, it explains how variable length arrays work (guess things are still valid for version > 2.8.1) Also I have tried the command: gcc -ansi -pendantic -c vla.cpp where - vla.cpp contains code posted by Bob Wilson in the first message of the thread - gcc is the version 2.95.2 19991024 (the one shipped with Dev-C++ 4.0) and it gives the expected warning -- Luigi |
|
From: Bob W. <bo...@ph...> - 2002-05-02 16:02:35
|
Luigi, looking at some HTML files related to gcc 2.8.1 (I can't remember = where I got them), I found the file attached to this mail, it explains = how variable length arrays work (guess things are still valid for = version > 2.8.1) Thank you, thank you, thank you! In all my fumbling around I managed to = miss the GNU online manual. It should be able to answer many of my past = and future questions.=20 Also I have tried the command: gcc -ansi -pendantic -c vla.cpp=20 where - vla.cpp contains code posted by Bob Wilson in the first = message of the thread - gcc is the version 2.95.2 19991024 (the one shipped with Dev-C++ = 4.0) and it gives the expected warning Again, thank you or perhaps I should say "grazie." Bob Wilson |
|
From: Brian P. <br...@su...> - 2002-05-02 13:50:02
|
Actually, I am told that the full switch is: -ansi -pedantic-errors (but the person who told me this may simply be a pedant himself:) I didn't know this even existed. C99 allowed it in block scope (as opposed to mint flavored) but that supposedly made the code non-portable to c++ which brings up two things: a. I would hate to be the winner that got to port a huge c project to c++, b. If I had to move a large, real life C++ project from any other compiler to VC++ I think that the variable array would be the least of my worries. In fact, the only reason I can see (at this point) of porting from gnu to MS...er...O.k., I can't see one. Oh! Yea, it would be if I had to use the .NET stuff in VC++ 7. And anyone who has worked with VC++ .NET will wonder (as I did) if that can constitute C++ programming at all since microsoft isn't the king of "embrace and enhance" for nothing. b-- On Sat, 2002-04-20 at 03:20, Abhijit Shylanath wrote: > Quote Microsoft: "This isn't a bug, it's a feature." Seriously, though, t= his is one feature of the GCC compiler (I remember reading about it in the = DJGPP docs). If you're still looking for the compiler to stop when it encou= nters non-ANSI code, there must be a command-line options somewhere. Yup, = here it is... from the Dev-C++ help file. >=20 > -------------------------------------------------------------------------= ------- >=20 > - Support all ANSI C standard programs (compiler parameter : -ansi): >=20 > This turns off certain features of GNU C that are incompatible with ANSI = C, such as the asm, inline and typeof keywords, and predefined macros such = as unix and vax that identify the type of system you are using. It also en= ables the undesirable and rarely used ANSI trigraph feature, and it disable= s recognition of C++ style // comments. >=20 > -------------------------------------------------------------------------= ------- >=20 > But what the hell, GCC is kind of a standard in itself. > mdeth O > m.o.t.o[P.S.Y.C.H.O]=20 >=20 > http://mudeth.tripod.com | ibr...@bi... | mu...@gm... > ----- Original Message -----=20 > From: Bob Wilson=20 > To: Dev-C++ User Mailing List=20 > Sent: Saturday, April 20, 2002 3:29 AM > Subject: [Dev-C++] Dev-C++ Users Beware! >=20 >=20 > David, > An array is not dynamic, the value you pass it at initalization must = be a constat of some sort.if 'i' were to change during the program some wei= rd voodoo (the program will crash,the world will end,etc.) all this will ha= pen because it cannot change the size of an array at runtime(reason no. 1 l= inked lists were created) > I am in the process of learning C++, as Ioannis well knows, and a week = or so ago I was working on the array chapter. In the past I have done most = of my programming in pascal, and every pascal compiler I have used will not= compile an array if the size of the array is a variable, i.e., no dynamic = arrays. Just fooling around I modified the simple little C++ array program = to define an array with a variable. I had not done any research but was con= fident that the compiler would flag an error and bail out.=20 >=20 > Not So! the program compiled and ran allowing me to change the size of = the array. I tested the bounds of the program and could build quite large a= rrays. the size_of function always returnd the correct size of the array. I= was really surprised because that it worked. I have not employed the techn= ique in any real world program, because I felt that it would be much safer = with pointers and linked lists.=20 >=20 > Your message above confirmed what I suspected but had not taken the tim= e to investigate. Stroustrup says: > The number of elements of the array, the array bound, must be a const= ant expresseion (=A7C.5) > Paragraph C.5 says in part: > A constant expression evaluates to an integral of enumeration constan= t. Such an expression is composed of literals, enumerators, and const initi= alized by constant expressions. < . . . > Intuitively, constant expressions= are simple expressions that can be evaluated by the compiler before the pr= ogram is linked and starts to run. > That tells me that the compiler should have caught this and bailed out = rather than compiling, linking, and running this program:=20 >=20 > #include <iostream.h> > #include <stdlib.h> >=20 > int main > { > int arraySize =3D 1; > std::cout << "Enter the size of the array: "; > std::cin >> arraySize; > if (!(arraySize > 0)) > { > system("pause"); > return 0; > } > int myArray[arraySize]; > int arrayLength =3D sizeof(myArray)/sizeof(myArray[0]); > for (int i=3D0; i < arrayLength; i++) // 0 to arrayLength-1 > { > myArray[i] =3D (i + 1) * 2 + 1; > } > for (int i=3D0; i< arrayLength; i++) // 0 to arrayLength-1 > { > std::cout << i << ": " << myArray[i] << "\n"; > } > =20 > system("pause"); > return 0; > } > The faulty compiler is the one used by Bloodshed. Visual C++ 6.0 caught= the error. That is the second and most serious problem I have found with t= he compiler used by the dev-c++ environment. It appears it will properly co= mpile ANSI standard code, but it will also compile code that is clearly out= side of the standard.=20 >=20 > I believe that the dev-c++ compiler is the mingw compiler.=20 >=20 > Regards, >=20 > Bob Wilson >=20 |