Chapter Contents

Previous

Next
SAS/C C++ Development System User's Guide, Release 6.50


Header Files

Most C++ programs need to access some of the classes and functions contained in the libraries provided with the SAS/C C++ Development System. These classes and functions are declared in header files. In addition, you can have header files of your own. Using the SAS/C C++ Development System under TSO, CMS, MVS Batch, and OpenEdition , describes how header files are stored and named under your operating system. Here are some other tips to keep in mind when you use header files in C++ programs:



Header Files Supplied with the Standard Libraries

The following header files are supplied with the standard libraries:

complex.h iostream.h strstream.h
bsamstr.h new.h typeinfo.h
fstream.h stream.h
iomanip.h stdiostream.h

 

Except for new.h ,  stream.h , and  typeinfo.h , the contents of these header files are described in I/O Class Descriptions . The contents of  stream.h are described in stream.h header file . 


new.h Header File

The contents of new.h are as follows:  

void* operator new(size_t size)
 allocates a block of dynamic memory of size bytes. If insufficient free dynamic memory is available and a new-handler is currently defined, the new-handler is called. When the new-handler returns, operator new tries again to allocate memory, and if that fails, it again calls the new-handler. This process repeats until either  operator new can allocate some dynamic memory or the new-handler is removed.

 void * operator new(size_t size, 
void* location);
  does not allocate memory, but instead ignores the size argument and simply returns the  location argument as its result. This version of  operator new is used to construct objects at a specified location.

  void operator delete(void* ptr)
 frees the block of dynamic memory pointed to by ptr .

 void (*set_new_handler (void(*handler)()))()
 defines a user-defined function (a new-handler) to handle out-of-memory conditions detected by operator new . The new-handler is called if  operator new cannot allocate any dynamic memory. The new-handler function takes no arguments and returns  void . The new-handler should free some memory before returning to its caller, or an endless loop could result. If it cannot free any memory, it should terminate the program via  exit or  abort . Another alternative is to remove itself as a new-handler by calling  set_new_handler with NULL or a pointer to some other handler.  set_new_handler returns the previous new-handler or NULL if there was not a previous new-handler.

 

typeinfo.h Header File

The class, functions, and types declared in the typeinfo.h header file are provided to identify and compare types, and to control run time error handling for Run Time Type Identification, or RTTI. The class  type_info is declared in this header file. A description of the functions, operators, and types found in  class type_info is included in this section. Release 6.50 of the SAS/C C++ Development System does not support exceptions so a mechanism corresponding to default handling of an exception is invoked for these errors. Descriptions of the run time error handling type  terminate_handler and functions  set_terminate, and  terminate are also included in this section. 

See Appendix 4 for more information on RTTI.

class type_info

Provides information on object types

SYNOPSIS
 #include <typeinfo.h>

class type_info
{
public:
   virtual ~type_info();

   int operator==(const type_info& rhs) const;
   int operator!=(const type_info& rhs) const;

   int before(const type_info& rhs) const;

   const char* name() const;
};

DESCRIPTION
This class is declared in <typeinfo.h> . The RTTI operator  typeid() returns a reference to a  const object of this type. Such objects are created by the C++ implementation to provide an identifier for types. The class allows two  type_info objects to be compared for type equivalence, or compared for order in an arbitrary collating sequence of types. It also allows a printable description of the represented type to be retrieved.

 CONSTRUCTORS
This class has no public constructors.

DESTRUCTORS
The destructor is virtual, so the class is polymorphic itself.

NONVIRTUAL MEMBER FUNCTIONS

int operator==(const type_info& rhs) const;
 returns 1 if the two type_info objects represent the same type, and returns 0 otherwise.

 int operator!=(const type_info& rhs) const;
 returns 0 if the two type_info objects represent the same type, and returns 1 otherwise.

 int before(const type_info& rhs) const;
 returns 1 if the type represented by this object precedes the type represented by rhs in an arbitrary collating sequence of types, and returns 0 otherwise. This order is arbitrary and may change in different program loads.

 const char* name() const;
 returns a pointer to a character string containing a human readable representation of the type represented by the type_info object. The function calls operator  new to allocate working storage. The result is cached so it should not be deallocated by the user.

 

set_terminate, terminate_handler, and terminate

Provide runtime error handling for RTTI

SYNOPSIS
 #include <typeinfo.h>

typedef void (*terminate_handler)();
terminate_handler set_terminate
    (terminate_handler new_handler);
void terminate();

DESCRIPTION
In this release, these functions and types are used to control run-time error handling for RTTI. (In ISO C++ they are part of a more general exception handling mechanism.):

terminate_handler
 a type representing a handler function. A handler function is called when terminate() is called. The handler function must end the program without returning.

  old_handler = set_terminate(new_handler);
 Sets a user specified terminate handler which can be used to perform cleanup before terminating program execution. The new handler pointer must not be NULL. The old handler value is returned.

terminate();
 calls the termination handler. This function is effectively called under various conditions when a C++ exception can not be handled. C++ exceptions are not supported in this release, but RTTI operations can detect erroneous conditions wh ich are normally handled by throwing an exception. In this release, the RTTI operations, in effect, call terminate() . The default handler calls  abort() .


Chapter Contents

Previous

Next

Top of Page

Copyright © Tue Feb 10 12:11:23 EST 1998 by SAS Institute Inc., Cary, NC, USA. All rights reserved.