/////////////////////////////////////////////////////////////////////////////// // // StackOvfDemo.cpp // // Author: Oleg Starodumov (www.debuginfo.com) // // This application simulates a stack overflow exception // // /////////////////////////////////////////////////////////////////////////////// // Include files // #include #include #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// // Type definitions // typedef std::vector StringVec_t; /////////////////////////////////////////////////////////////////////////////// // Function declarations // void GetStringsA( StringVec_t& Strings ); void ProcessStrings( const StringVec_t& Strings ); void ProcessStringW( const wchar_t* pString ); /////////////////////////////////////////////////////////////////////////////// // main() // int main( int argc, char* argv[] ) { // Print header printf( "Stack Overflow Demo.\n\n" ); // Do the work // Get a number of strings (in ANSI format) StringVec_t Strings; GetStringsA( Strings ); // Process the strings ProcessStrings( Strings ); // Complete return 0; } /////////////////////////////////////////////////////////////////////////////// // Functions // void GetStringsA( StringVec_t& Strings ) { // Simply create a relatively large collection of long strings for( int i = 0; i < 1000; i++ ) { Strings.push_back( std::string( 1000, 'a' ) ); } } void ProcessStrings( const StringVec_t& Strings ) { USES_CONVERSION; // For each string for( size_t i = 0; i < Strings.size(); i++ ) { // Convert the string to Unicode const wchar_t* pStringW = A2W( Strings[i].c_str() ); // Process the string in Unicode format ProcessStringW( pStringW ); } } void ProcessStringW( const wchar_t* pString ) { // The "processing" simply means reporting the string to stdout if( pString != 0 ) wprintf( pString ); }