[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

Chapter 25.

 

<mslconfig>



The MSL header <mslconfig> contains a description of the macros and defines that are used as switches or flags in the MSL C++ library.


Overview of the C++ Switches, Flags and Defines

The MSL C++ library has various flags that may be set to customize the library to users specifications these include:


_CSTD

The _CSTD macro evaluates to::std if the MSL C library is compiled in the std namespace, and to nothing if the MSL C library is compiled in the global namespace.

_STD and _CSTD are meant to prefix C++ and C objects in such a way that you don't have to care whether or not the object is in std or not. For example:

_STD::cout, or _CSTD::size_t.


_Inhibit_Container_Optimization

If this flag is defined it will disable pointer specializations in the containers. This may make debugging easier.


NOTE

You must recompile the C++ lib when flipping this switch.



_Inhibit_Optimize_RB_bit

Normally the red/black tree used to implement the associative containers has a space optimization that compacts the red/black flag with the parent pointer in each node (saving one word per entry). By defining this flag, the optimization is turned off, and the red/black flag will be stored as an enum in each node of the tree.


_MSL_ARRAY_AUTO_PTR

When defined auto_ptr can be used to hold pointers to memory obtained with the array form of new.

The syntax looks like:

auto_ptr<string, _Array<string> >
   pString(new string[3]);
  pString.get()[0] = "pear";
  pString.get()[1] = "peach";
  pString.get()[2] = "apple";

Without the _Array tag, auto_ptr behaves in a standard fashion. This extension to the standard is not quite conforming as it can be detected through the use of template template arguments.


NOTE

This extension can be disabled by not defining _MSL_ARRAY_AUTO_PTR.



__MSL_CPP__

Evaluates to an integer value which represents the C++ lib's current version number.


TIP

This value is best when read in hexidecimal format



_MSL_EXTENDED_BINDERS

Defining this flag adds defaulted template parameters to binder1st and binder2nd. This allows client code to alter the type of the value that is stored. This is especially useful when you want the binder to store the value by const reference instead of by value to save on an expensive copy construction.

For example:


#include <string>
#include <functional>
#include <algorithm>
struct A
{
public:
	A(int data = 0) : data_(data) {}
	friend bool operator < (const A& x, const A& y) {return x < y;}
	private:
	int data_;
	A(const A&);
};

int main()
{
using namespace std;
	A a[5];
	A* i = find_if(a, a+5, binder2nd<less<A> >(less<A>(), A(5)));
}

This causes the compile-time error, because binder2nd is attempting to store a copy of A(5). But with _MSL_EXTENDED_BINDERS you can request that binder2nd store a const A& to A(5).


A* i = find_if(a, a+5, 
	binder2nd<less<A>, const A&>(less<A>(), A(5)));


TIP

This may be valuable when A is expensive to copy.


This also allows for the use of polymorphic operators by specifying reference types for the operator.


NOTE

This extension to the standard is detectable with template template parameters so it can be disabled by not defining _MSL_EXTENDED_BINDERS.



_MSL_EXTENDED_PRECISION_OUTP

When defined this allows the output of floating point output to be printed with precision greater than DECIMAL_DIG. With this option, an exact binary to decimal conversion can be performed (by bumping precision high enough).


TIP

The cost is about 5-6Kb in code size.



NOTE

You must recompile the C++ lib when flipping this switch.



_MSL_FORCE_ENABLE_BOOL_SUPPORT

This tri-state flag has the following properties

If _MSL_FORCE_ENABLE_BOOL_SUPPORT is defined, the C++ library will internally ignore the "Enable bool support" setting in the application's language prefereences panel, despite the fact that most of the C++ library is compiled into the application (since it is in headers) instead of into the binary C++ library.

The purpose of this flag is (when defined) to avoid having to recompile the C++ library when "Enable bool" support is changed in the language prefences panel.

With _MSL_FORCE_ENABLE_BOOL_SUPPORT defined to one, std::methods will continue to have a real bool in their signature, even when bool support is turned off in the application. But the user won't be able to form a bool (or a true/false). He won't be able to:


  bool b = std::ios_base::sync_with_stdio(false);    // error: undefined bool and false


NOTE

Changing this flag will require a recompile of the C++ library.


With _MSL_FORCE_ENABLE_BOOL_SUPPORT on, std::methods will continue to have a real bool in their signature, even when bool support is turned off in the application. But the user won't be able to form a bool (or a true/false). He won't be able to:


  bool b = std::ios_base::sync_with_stdio(false);   // error: undefined bool and false

but this will work:


  unsigned char b =   std::ios_base::sync_with_stdio(0);

And the C++ lib will link instead of getting the ctype link error.


_MSL_FORCE_ENUMS_ALWAYS_INT

This tri-state flag has the following properties

If _MSL_FORCE_ENUMS_ALWAYS_INT is defined, the C++ library will internally ignore the "Enums always int" setting in the application's language prefs, despite the fact that most of the C++ library is compiled into the application (since it is in headers) instead of into the binary C++ library.

The purpose of this flag is (when defined) to avoid having to recompile the C++ lib when "Enums always int" is changed in the language preferences panel.

For example, with _MSL_FORCE_ENUMS_ALWAYS_INT defined to zero, and if the user turns "enums always int" on in his language preferences panel, then any enums the user creates himself will have an underlying int type.

This can be exposed by printing out the sizeof(the enum) which will be four. However if the user prints out the sizeof(a std::enum), then the size will be one(because all std::enums fit into 8 bits) despite the enums_always_int setting.


NOTE

Changing this flags will require a recompile of the C++ lilibrary.



_MSL_IMP_EXP

The C, C++, SIOUX and runtime shared libraries have all been combined into one shared library locating under the appropriate OS support folder.

The exports files (.exp) have been removed. The prototypes of objects exported by the shared lib are decorated with a macro:


  _MSL_IMP_EXP_xxx   or
  _MSL_IMP_EXP_xxx
  //where xxx is the library designation.

which can be defined to __declspec(dllimport).

This replaces the functionality of the.exp/.def files. Additionally, the C, C++, SIOUX and runtimes can be imported separately by defining the following 4 macros differently:


  _MSL_IMP_EXP_C   _MSL_IMP_EXP_CPP
  _MSL_IMP_EXP_SIOUX
  _MSL_IMP_EXP_RUNTIME

Define these macros to nothing if you don't want to import from the associated lib, otherwise they will pick up the definition of _MSL_IMP_EXP.


NOTE

There is a header <UseDLLPrefix.h> that can be used as a prefix file to ease the use of the shared lib. It is set up to import all 4 sections.



WARNING!

There is a problem with non-const static data members of templated classes when used in a shared lib. Unfortunately <locale> is full of such objects. Therefore you should also define _MSL_NO_LOCALE which turns off locale support when using the C++ lib as a shared lib. This is done for you in <UseDLLPrefix.h>. See "_MSL_NO_LOCALE" for more details.



__MSL_LONGLONG_SUPPORT__

When defined, C++ supports long long and unsigned long long integral types. Recompile the C++ lib when flipping this switch.


_MSL_NO_BOOL

If defined then bool will not be treated as a built-in type by the library. Instead it will be a typedef to unsigned char (with suitable values for true and false as well). If _MSL_FORCE_ENABLE_BOOL_SUPPORT is not defined then this flag will set itself according to the "Enable bool support" switch in the language pref panel.


NOTE

The C++ lib must be recompiled when flipping this switch.



WARNING!

When _MSL_NO_BOOL is defined, vector<bool> will really be a vector<unsigned char>, thus it will take up more space and not have flip methods.Also there will not be any traits specializations for bool (i.e. numeric_limits).



_MSL_NO_CPP_NAMESPACE

If defined then the C++ lib will be defined in the global namespace.


NOTE

You must recompile the C++ lib when flipping this switch.



_MSL_NO_EXCEPTIONS

If defined then the C++ lib will not throw an exception in an exceptional condition. Instead void __msl_error(const char*); will be called. You may edit this inline in <mslconfig> to do whatever is desired. Sample implementations of __msl_error are provided in <mslconfig>.


NOTE

The operator new (which is in the runtime libraries) is not affected by this flag.


Remarks:

This flag detects the language pref panel "Enable C++ exceptions" and defines itself if this option is not on.


NOTE

The C++ lib must be recompiled when changing this flag (including if the language preference panel is changed).



_MSL_NO_EXPLICIT_FUNC_TEMPLATE_ARG

When defined assumes that the compiler does not support calling function templates with explicit template arguments.

On Windows, when ARM Conformance is selected in the language prefs panel, then this switch is automatically turned on. The Windows compiler goes into a MS compatible mode with ARM on.

This mode does not support explicit function template arguments.

In this mode, the signatures of has_facet and use_facet change.

Example of _MSL_NO_EXPLICIT_FUNC_TEMPLATE_ARG usage::


Standard setting:
template <class Facet> 
	const Facet& use_facet(const locale& loc);
template <class Facet> 
	bool has_facet(const locale& loc) throw();





_MSL_NO_EXPLICIT_FUNC_TEMPLATE_ARG setting.
template <class Facet> 
	const Facet& use_facet(const locale& loc, Facet*);
template <class Facet> 
	bool has_facet(const locale& loc, Facet*) throw();

 



NOTE

You must recompile the C++ lib when flipping this switch.



_MSL_NO_IO

 

If this flag is defined the C++ will not support any I/O (not

even stringstreams).


_MSL_NO_LOCALE

 

When this flag is defined, locale support is stripped from the

library. This has tremendous code size benefits.

 

All C++ I/O will implicitly use the "C" locale. You may not create

locales or facets, and you may not call the imbue method on a

stream. But otherwise all streams are completely functional.


NOTE

The C++ lib must be recompiled when flipping this switch.



_MSL_NO_REFCOUNT_STRING

 

This flag will reconfigure basic_string so that it is not refcounted.

This may have code size savings. It may or may not have performance

benefits. Benefits of this switch are highly application dependent.


NOTE

You must recompile the C++ lib when flipping this switch.



_MSL_USE_AUTO_PTR_96

 

Defining this flag will disable the standard auto_ptr and enable

the version of auto_ptr that appeared in the Dec.'96 CD2.


_MSL_NO_VECTOR_BOOL

 

If this flag is defined it will disable the standard vector<bool> partial specialization. You can still instantiate vector<bool>, but it will not have the space optimization of one bool per bit.


NOTE

There is no need to recompile the C++ lib when flipping this switch,

but you should remake any precompiled headers you might be using.



_MSL_NO_WCHART

 

If defined then the C++ library will not support any wide character

functionality (such as wide streams or wide strings).

 

This flag detects the language pref panel "Enable wchar_t support"

and defines itself if support is turned off.


NOTE

The C++ library must be recompiled when turning this switch on

(but need not be recompiled when turning it off).



_STD

 

This macro evaluates to::std if the C++ lib is compiled in the

std namespace, and to nothing if the C++ lib is compiled in the

global namespace.

See Also:

"_CSTD"

 

 

 

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000