Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Substitute STL in VS 6.0?

Status
Not open for further replies.

drdad5727

Programmer
Feb 28, 2005
28
US
Has anyone tried to use an STL other than Microsoft's with Visual Studio 6.0? I tried using SGI's by putting the include directory as the first in the "additional include directories" list and got a ga-zillion error messages tagged to Microsoft header files I'd never heard of. Anyone have success in doing this? (I'd really like a hash map....)

 
Don't replace MS STL. Just get the latest updates for it. They cover the cin/string problem and a few other fixes.

If you want hash maps, try boost. It is compatible with all versions of STL. Look for hashmap, not hash map. The annoying bit is you'll have to get the whole boost library first. You can't just download the hashmap template.

Another alternative is to use MFC maps. They are internally hashmaps and one of the few MFC things I use in preference to STL as it is so much faster.

Failing that, go for VS2003 or 2005. They have hashmaps but it is under ste (std extension) not std.

 
Also don't forget to set the initial size of your hash table. The default is something stupid like 11.
 
Actually, I'd look for unordered_map, because that is pseudo-standardized already and will be part of the next standard. The different hash map interfaces are different, so its best to go with the one that will be the "official" C++ version going forward.

We have changed STL libraries in VC++ 6.0 a few years ago (we have since upgraded to VC++ 2003). We had issues, possibly including "a ga-zillion error messages tagged to Microsoft header files". If you want to continue to try to use that library perhaps you can post an example of your error messages.
 
VC++ 6.0 sucks when it comes to STL, even with the latest service packs... You need to add a ton of #pragma statements to your code to get rid of all the warnings it produces. Upgrade to the latest version of VC++.
Otherwise, you can use these header files instead of the VC++ 6.0 headers -- they just enable all the #pragma statements before including the STL header...

Code:
// stl_algorithm.h
#ifndef STL_ALGORITHM_HEADER
#define STL_ALGORITHM_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4100)	// unreferenced formal parameter.

#	include <algorithm>

#	pragma warning(pop)
#else
#	include <algorithm>
#endif	// _MSC_VER <= 1200

#endif	// STL_ALGORITHM_HEADER

Code:
// stl_fstream.h
#ifndef STL_FSTREAM_HEADER
#define STL_FSTREAM_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
	// These warnings must be disabled permanently.
#	pragma warning(disable: 4701)	// local variable '_C' may be used without having been initialized.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.

#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4097)	// typedef-name 'identifier1' used as synonym for class-name 'identifier2'.
#	pragma warning(disable: 4127)	// conditional expression is constant.
#	pragma warning(disable: 4702)	// unreachable code.

#	include <fstream>

#	pragma warning(pop)
#else
#	include <fstream>
#endif	// _MSC_VER <= 1200

#endif	// STL_FSTREAM_HEADER

Code:
// stl_iomanip.h
#ifndef STL_IOMANIP_HEADER
#define STL_IOMANIP_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)

#	include <iomanip>

#	pragma warning(pop)

#else
#	include <iomanip>
#endif	// _MSC_VER <= 1200

#endif	// STL_IOMANIP_HEADER

Code:
// iostream.h
#ifndef STL_IOSTREAM_HEADER
#define STL_IOSTREAM_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
	// Unfortunately, this warning must be permanently disabled.
#	pragma warning(disable: 4514)	// unreferenced inline/local function has been removed.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.

#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	include <iostream>

#	pragma warning(pop)
#else
#	include <iostream>
#endif	// _MSC_VER <= 1200

#endif	// STL_IOSTREAM_HEADER

Code:
// stl_iterator.h
#ifndef STL_ITERATOR_HEADER
#define STL_ITERATOR_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4284)	// return type for 'identifier::operator –>' is not a UDT or reference to a UDT. Will produce errors if applied using infix notation.

#	include <iterator>

#	pragma warning(pop)
#else
#	include <iterator>
#endif	// _MSC_VER <= 1200

#endif	// STL_ITERATOR_HEADER

Code:
// stl_list.h
#ifndef STL_LIST_HEADER
#define STL_LIST_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4284)	// return type for 'identifier::operator ->' is not a UDT or reference to a UDT.  Will produce errors if applied using infix notation.
#   pragma warning(disable: 4702)	// Unreachable code in release.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	include <list>

#	pragma warning(pop)
#else
#	include <list>
#endif	// _MSC_VER <= 1200

#endif	// STL_LIST_HEADER

Code:
// stl_map.h
#ifndef STL_MAP_HEADER
#define STL_MAP_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
// This warning must be permanently disabled.
#	pragma warning(disable: 4503)	// 'decorated name length exceeded, name was truncated.

#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4512)	// 'class' : assignment operator could not be generated.
#	pragma warning(disable: 4663)	// C++ language change: to explicitly specialize class template 'vector'.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

// BUG: C4786 Warning Is Not Disabled with #pragma Warning
// STATUS: Microsoft has confirmed this to be a bug in the Microsoft product. 
// This warning can be ignored. This occured only in the <map> container.

#	include <map>

#	pragma warning(pop)
#else
#	include <map>
#endif	// _MSC_VER <= 1200

#endif	// STL_MAP_HEADER

Code:
// stl_memory.h
#ifndef STL_MEMORY_HEADER
#define STL_MEMORY_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	include <memory>

#	pragma warning(pop)
#else
#	include <memory>
#endif	// _MSC_VER <= 1200

#endif	// STL_MEMORY_HEADER

Code:
// stl_new.h
#ifndef STL_NEW_HEADER
#define STL_NEW_HEADER

#include <new>

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
	// Must permanently disable these errors.  :(
#	pragma warning(disable: 4290)	// 'C++ Exception Specification ignored'.
#	pragma warning(disable: 4514)	// 'unreferenced inline function has been removed'.

#	pragma once
#	include <cstdlib>	// For malloc() & free().
#	include <malloc.h>	// For malloc() & free().


void* operator new( size_t  size ) throw( std::bad_alloc )
{
	void* pTemp = malloc( size );
	
	if ( pTemp == NULL )
	{
		throw std::bad_alloc();
	}

	return pTemp;
}

void* operator new[]( size_t  size ) throw( std::bad_alloc )
{
	void* pTemp = malloc( size );
	
	if ( pTemp == NULL )
	{
		throw std::bad_alloc();
	}

	return pTemp;
}

void* operator new( size_t  size, std::nothrow_t& ) throw()
{
	return malloc( size );
}

void* operator new[]( size_t  size, std::nothrow_t& ) throw()
{
	return malloc( size );
}

void operator delete( void*  pObject ) throw()
{
	if ( pObject != NULL )
	{
		free( pObject );
	}
}

void operator delete[]( void*  pObject ) throw()
{
	if ( pObject != NULL )
	{
		free( pObject );
	}
}

void operator delete( void*  pObject, std::nothrow_t& ) throw()
{
	if ( pObject != NULL )
	{
		free( pObject );
	}
}

void operator delete[]( void*  pObject, std::nothrow_t& ) throw()
{
	if ( pObject != NULL )
	{
		free( pObject );
	}
}

#endif	// _MSC_VER <= 1200

#endif	// STL_NEW_HEADER

Code:
// stl_set.h
#ifndef STL_SET_HEADER
#define STL_SET_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)

#	include <set>

#	pragma warning(pop)
#else
#	include <set>
#endif	// _MSC_VER <= 1200

#endif	// STL_SET_HEADER

Code:
// stl_sstream.h
#ifndef STL_SSTREAM_HEADER
#define STL_SSTREAM_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4097)	// typedef-name 'identifier1' used as synonym for class-name 'identifier2'.
#	pragma warning(disable: 4127)	// conditional expression is constant.

#	include <sstream>

#	pragma warning(pop)
#else
#	include <sstream>
#endif	// _MSC_VER <= 1200

#endif	// STL_SSTREAM_HEADER

Code:
// stl_stack.h
#ifndef STL_STACK_HEADER
#define STL_STACK_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	include <stack>

#	pragma warning(pop)
#else
#	include <stack>
#endif	// _MSC_VER <= 1200

#endif	// STL_STACK_HEADER

Code:
// stl_stdexcept.h
#ifndef STL_STDEXCEPT_HEADER
#define STL_STDEXCEPT_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
	// This warning must be permanently disabled.
#	pragma warning(disable: 4290)	// C++ Exception Specification ignored.

#	pragma once
#endif	// _MSC_VER <= 1200

#include <stdexcept>

#endif	// STL_STDEXCEPT_HEADER

Code:
// stl_string.h
#ifndef STL_STRING_HEADER
#define STL_STRING_HEADER

// Disable warnings produced by Visual Studio.  The warnings are re-enabled at
// the end of this file.
#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
	// These must be permanently disabled.  :(
#	pragma warning(disable: 4503)	// 'decorated name length exceeded, name was truncated.
#	pragma warning(disable: 4514)	// unreferenced inline/local function has been removed.
#	pragma warning(disable: 4701)	// Local variable 'name' may be used without having been initialized.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4146)	// unary minus operator applied to unsigned type, result still unsigned.
#	pragma warning(disable: 4183)	// 'at': member function definition looks like a ctor, but name does not match enclosing class.
#	pragma warning(disable: 4244)	// 'conversion' conversion from 'type1' to 'type2', possible loss of data.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4511)	// 'class' : copy constructor could not be generated.
#	pragma warning(disable: 4512)	// 'class' : assignment operator could not be generated.
#	pragma warning(disable: 4663)	// C++ language change: to explicitly specialize class template 'vector'.

#	include <string>

#	pragma warning(pop)
#else
#	include <string>
#endif	// _MSC_VER <= 1200

#endif	// STL_STRING_HEADER

Code:
// stl_vector.h
#ifndef STL_VECTOR_HEADER
#define STL_VECTOR_HEADER

#if defined( _MSC_VER ) && (_MSC_VER <= 1200)	// 1200 = MSVC 6.0.
#	pragma once
#	pragma warning(push, 3)
#	pragma warning(disable: 4018)	// signed/unsigned mismatch.
#	pragma warning(disable: 4100)	// unreferenced formal parameter.
#	pragma warning(disable: 4245)	// conversion from 'type1' to 'type2', signed/unsigned mismatch.
#	pragma warning(disable: 4663)	// C++ language change: to explicitly specialize class template 'vector'.
#	pragma warning(disable: 4702)	// unreachable code.
#	pragma warning(disable: 4710)	// 'function' : function not inlined.
#	pragma warning(disable: 4786)	// identifier was truncated to 'number' characters in the debug information.

#	include <vector>

#	pragma warning(pop)
#else
#	include <vector>
#endif	// _MSC_VER <= 1200

#endif	// STL_VECTOR_HEADER
 
It seems my problem is more complex than I thought. The project I'm working on hosts an ActiveX control using ATL. The errors I'm getting when I use the SGI STL implementation all come from the comip.h header file, which is "Native C++ compiler COM support" according to it's comments. I certainly didn't include this header and I don't know who did. Here are some representative errors:
Code:
c:\program files\microsoft visual studio\vc98\include\comip.h(31) : error C2061: syntax error : identifier '_Interface'
c:\program files\microsoft visual studio\vc98\include\comip.h(49) : error C2992: '_com_IIID' : invalid or missing template parameter list
        c:\program files\microsoft visual studio\vc98\include\comip.h(49) : see declaration of '_com_IIID'
c:\program files\microsoft visual studio\vc98\include\comip.h(51) : error C2061: syntax error : identifier '_IIID'
c:\program files\microsoft visual studio\vc98\include\comip.h(785) : error C2992: '_com_ptr_t' : invalid or missing template parameter list
        c:\program files\microsoft visual studio\vc98\include\comip.h(785) : see declaration of '_com_ptr_t'
c:\program files\microsoft visual studio\vc98\include\comip.h(789) : error C2061: syntax error : identifier '_InterfaceType'
c:\program files\microsoft visual studio\vc98\include\comip.h(789) : error C2065: '_InterfaceType' : undeclared identifier
c:\program files\microsoft visual studio\vc98\include\comip.h(798) : error C2061: syntax error : identifier '_Interface'
c:\program files\microsoft visual studio\vc98\include\comip.h(798) : error C2061: syntax error : identifier '_Interface'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top