Compiler flags in Linux

Hello,

Anybody knows where I can get documentation on the meanings/purpose
of the various C++ compiler flags that can be used,

==============

-DLIN -DLININTEL -DNO_CXX_EXCEPTION -funsigned-char -O3 -DNo_Exception -Wall -DCAS5 -DHAVE_CONFIG_H -fPIC -MD -DCSFD -DNOPROTECTION -DNDEBUG -DHAVE_WOK_CONFIG_H -Wno-deprecated

================

For eg. what is the purpose of "-DNO_CXX_EXCEPTION" and "DNo_Exception" ?

Bearloga's picture

To know about NO_CXX_EXCEPTION, see the comments in Standard_ErrorHandlerCallback.cdl, and also see the code in Standard_ErrorHandler.lxx.

To understand the meaning of No_Exception, look, for example, at the definition of the method Value() of the generic class TCollection_Array1:

Standard_OutOfRange_Raise_if((Index < myLowerBound || Index > myUpperBound),NULL);
return ((Array1Item *)myStart)[Index];

And then look at the definition of the macro Standard_OutOfRange_Raise_if:

#if !defined No_Exception && !defined No_Standard_OutOfRange
#define Standard_OutOfRange_Raise_if(CONDITION,MESSAGE) \
if (CONDITION) Standard_OutOfRange::Raise(MESSAGE);
#else
#define Standard_OutOfRange_Raise_if(CONDITION,MESSAGE)
#endif

You see, with No_Exception there is no check for array bounds in the method Value.

PG's picture

Thanks for the responses.

What I have observed with the "NO_CXX_EXCEPTION" flag if removed
from the 'Makefile' in the compiler flags, then the
try/catch of OCC 'Standard_failure' for various API's
works successfully.
What I mean is OCC API 'Standard_COnstructuionError' is
caught and thrown.

Bearloga's picture

Without NO_CXX_EXCEPTION on Linux you will face serious problems with catching system signals such as SIGSEGV, SIGFPE, etc., when using OSD::SetSignal method to redirect signals.
But, since OCC6.2 a new mechanism appeared that is initiated with the definition OCC_CONVERT_SIGNALS instead of NO_CXX_EXCEPTION, and it seams to be more safe as it uses the native C++ try/catch and thus unwinds all objects on the stack during treatment of any exception or signal.
To use any of these mechanisms you need to include the header Standard_ErrorHandler.hxx in any source file containing try/catch clauses, and additionally to use the last mechanism you need to insert OCC_CATCH_SIGNALS macro just after each 'try' clause. For example, see any OCC source file containg 'try'.

PG's picture

Hello all,

Anybody can share a makefile with latest/new compiler flags for Linux/windows.

thanks in advance

- PG

kraftche's picture

The ones of the form -Dfoo are equivalent to doing "#define foo" in the source. Most of them are OpenCascade-specific. -DNDEBUG removes all "assert" statements from the code.

The -W flags enable/disable warnings.

-O3 is an optimization level.

-fPIC requests position-independent code, typically for shared libraries.

-funsignned-char presumably does exactly what it says: makes "char" and unsigned type [0,255] rather than a signed type [-128,127].

kraftche's picture

The ones of the form -Dfoo are equivalent to doing "#define foo" in the source. Most of them are OpenCascade-specific. -DNDEBUG removes all "assert" statements from the code.

The -W flags enable/disable warnings.

-O3 is an optimization level.

-fPIC requests position-independent code, typically for shared libraries.

-funsignned-char presumably does exactly what it says: makes "char" and unsigned type [0,255] rather than a signed type [-128,127].

But to answer your actual question: to get documentation on the g++ compiler flags try the command "man g++", or "info g++". As for the OpenCascade-specific preprocessor defines, you'll probably have to search the source for the places where they are used.