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


Checking for Resources To Initialize Static Data

Sometimes you create static C++ objects that require certain resources, such as a floating-point unit (FPU). You can check for these resources by creating a function called __PreInit__() which the compiler calls before it initializes static data. You cannot check for these resources in your main() routine, because the compiler initializes static data before it calls main().

You must declare the __PreInit__() function like this:


extern "C" void __PreInit__(void);


NOTE

This function is not supported when generating code for PowerPC.

For example, this stub checks for a floating-point unit. In this case you would also have to define the functions HasFPU() and DisplayNoFPU() yourself.

Checking for an FPU before initializing static data:
#include <Types.h>
#include <stdlib.h>

extern "C" void __PreInit__(void);

void __PreInit__(void)
{
  if(!HasFPU())   {
    DisplayNoFPU();  // Display "No FPU" Alert
    abort();         // Abort program exection
  }
}  


[ 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: August 17, 2000