Re: problem with -Wunreachable-code
Re: problem with -Wunreachable-code
- Subject: Re: problem with -Wunreachable-code
- From: Cameron Hayne <email@hidden>
- Date: Sat, 22 Jul 2006 06:54:20 -0400
On 21-Jul-06, at 11:54 PM, Eric Albert wrote:
If you find warnings in Apple's headers when compiling C99 code,
please file bugs. We're always interested in hearing about those
cases. -pedantic is an exception to that, by the way; I'm
disappointed that the static code analysis article recommended it.
One reason for the use of -pedantic is to check for non-standard-
conforming code. Unfortunately, the GNU compiler doesn't give errors
or even warnings for code that doesn't meet the ISO standards for C++
when you just use "-std=c++98". You need to use "-pedantic -std=c+
+98" to get it to reject non-standard code like the following:
---------------------------------------------------
#include <iostream>
using std::cout;
using std::endl;
#include <time.h>
// This tests whether dynamically allocated arrays are allowed.
// Compile it with "-pedantic -std=c++98" to get the C++98 standard
// Note that the default for g++ is "-std=gnu++98" which adds GNU
extensions
int main()
{
srand(time(0));
int n = (rand() % 10) + 1;
cout << "n is " << n << endl;
int data[n]; // this statement is illegal in C++98
for (int i = 0; i < n; i++)
{
data[i] = rand();
}
for (int i = 0; i < n; i++)
{
cout << "data[" << i << "] is " << data[i] << endl;
}
return 0;
}
--
Cameron Hayne
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden