Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with -Wunreachable-code



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: http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden
References: 
 >problem with -Wunreachable-code (From: "James W. Walker" <email@hidden>)
 >Re: problem with -Wunreachable-code (From: "Sean McBride" <email@hidden>)
 >Re: problem with -Wunreachable-code (From: Eric Albert <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.