Hide menu
cadex::Base_EnvironmentChecker Class Reference

Checks consistency between build environment of the user and CAD Exchanger. More...

Static Public Member Functions

static bool CheckEnvironment (FILE *theErrorStream=0, const char *theMode="Release")
 Checks consistency of build environment. More...

Detailed Description

Checks consistency between build environment of the user and CAD Exchanger.

It is important that the user's code which uses CAD Exchanger SDK has been built in environment (compiler version and compilation mode) consistent with one used to build respective CAD Exchanger module. If the environment is inconsistent (e.g. a different compiler version has been used, or debug and release modes have been mixed) this may lead to undefined behavior in run-time. This includes abnormal termination with exceptions and therefore strongly complicates the debuggability of such errors.

The root-cause of such errors may in particular stem from different implementations of STL (Standard Template Library) between different compiler versions or even between debug and release modes of the same compiler. CAD Exchanger API does use some STL API (e.g. strings, streams and containers) and therefore can be vulnerable to such inconsistencies.

Therefore it is recommended that the developer using CAD Exchanger inserts a call to Base_EnvironmentChecker::CheckEnvironment() to assert consistency of environments, e.g. during initialization of work with the SDK. The following example demonstrates the check and outputs details to the standard error stream:

assert (anOK); //will abort immediately in debug mode
if (!anOK) {
//output some warning message and abort in release mode

The method is not intrusive, it includes comparison of two strings and one integer.

CAD Exchanger includes calls to CheckEnvironment() in the headers of some potentially vulnerable classes (e.g. Base_LoggerStreamAppender). To use them make sure the macro __CADEX_CHECK_BUILD_ENVIRONMENT has been defined when compiling source files including those headers.

Member Function Documentation

◆ CheckEnvironment()

bool cadex::Base_EnvironmentChecker::CheckEnvironment ( FILE *  theErrorStream = 0,
const char *  theMode = "Release" 

Checks consistency of build environment.

Compares user build environment and one used to build a CAD Exchanger library used in run-time. Returns true if the environment are consistent and false otherwise.

If returns false then uses fprintf() to print details of two environments into theErrorStream. If the latter is null then outputs to stderr.

No other parameters should be explicitly provided, their values must be automatically defined by the pre-processor during compilation.

Returns false if theCompiler strings mismatch with one auto-generated in CAD Exchanger build, or theCompilerVersion is less than one used in CAD Exchanger build.

static bool CheckEnvironment(FILE *theErrorStream=0, const char *theMode="Release")
Checks consistency of build environment.
Definition: Base_EnvironmentChecker.cxx:73