本文介绍了C ++ GCC4.4警告:数组下标是以上数组界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到GCC 4.4(MinGW的TDM版本)现在的跟随code产生这些警告:

Here's the code:

void Console::print( const std::string& str ) {
    	std::string newLine( str );
    	if( newLine.size() > MAX_LINE_LENGTH ) {
    		sf::Uint32 stringSize = newLine.size();
    		for( sf::Uint32 insertPos = MAX_LINE_LENGTH;
    				insertPos < stringSize; insertPos += MAX_LINE_LENGTH ) {
    			newLine.insert( insertPos, "\n" );
    		}
    	}

    	StringList tokens;
    	boost::split( tokens, newLine, boost::is_any_of("\n") );

    	for( StringList::iterator it = tokens.begin();
    			it != tokens.end(); ++it ) {
    		addLine( *it );
    	}
    }

Any ideas?


It is the optimizations that are doing it...

Also it appears to be this line which is causing it:

boost::split( tokens, newLine, boost::is_any_of("\n") );


Ah yes, I found it, it is the argument for boost::is_any_of(), by wrapping it in a string() constructor the warning goes away, thank you all for your help :)

boost::split( tokens, newLine, boost::is_any_of( string( "\n" ) ) );
解决方案

Got the same error. As a workaround I replaced

is_any_of(" ")

with

is_from_range(' ', ' ')

which might also be slightly more efficient.

这篇关于C ++ GCC4.4警告:数组下标是以上数组界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 03:33
查看更多