c++c-preprocessor

C++ preprocessor unexpected compilation errors


Please look at the following file: (it is a complete file)

#ifndef TEES_ALGORITHM_LIBRARY_WRAPPER_H
#define TEES_ALGORITHM_LIBRARY_WRAPPER_H

#ifdef _TEES_COMPILE_AS_LIB
#include <dfa\Includes\DFC_algorithms.hpp>
#include <DFA\FuzzyClassifier\FuzzyAlgorithmIntialization\InitFuzzyAlgorithm.hpp>
typedef teesalgorithm::tees_fuzzy_algorithms algorithms_switchyard_class;
#else
#include <DFA\Includes\commercial_algorithms.hpp>
//An incomplete class to hide implementation
class algorithms_switchyard_class;
#endif

class AlgorithmLibraryWrapper {
algorithms_switchyard_class * algorithmPtr_;

typedef teesalgorithm::tees_paramObj paramObj_type;
typedef teesalgorithm::tees_errorObj errorObj_type;  
typedef teesalgorithm::tees_statusObj statusObj_type;
typedef teesalgorithm::tees_dataObj dataObj_type;
typedef teesalgorithm::tees_outputObj outputObj_type;

public:

AlgorithmLibraryWrapper(const std::string& sAlgName, paramObj_type& paramObj,     errorObj_type& errObj, statusObj_type& statusObj, const char* sFilePath);
static bool dataReader(const std::string& sFileName, dataObj_type& dataObj,     errorObj_type& errObj, statusObj_type& statusObj);
bool runalgorithm(const dataObj_type& dataObj, outputObj_type& outObj, errorObj_type& errObj, statusObj_type& statusObj); 
~AlgorithmLibraryWrapper();

};


#ifdef _TEES_USE_COMPILED_ALGORITHM_LIB
#   ifdef _MSC_VER
    #if _MSC_VER < 1400  // If VC 2003
        #ifdef _DEBUG
            #error No AlgorithmLibWrapper libraries compiled for this version of VC
        #else
            #error No AlgorithmLibWrapper libraries compiled for this version of VC
        #endif
    #elif defined(UNDER_CE)  // Win CE
        #ifdef _DEBUG
            #pragma comment( lib, "AlgorithmLibWrapperCEd" )
        #else
            #pragma comment( lib, "AlgorithmLibWrapperCE" )
        #endif
    #else  // If VC 2005
        #ifdef _DEBUG
            #pragma comment( lib, "AlgorithmLibWrapperd" )
        #else
            #pragma comment( lib, "AlgorithmLibWrapper" )
        #endif
    #endif
#endif 
#endif


#endif //TEES_ALGORITHM_LIBRARY_WRAPPER_H

I am getting the following errors; I don't know why. I manually counted the preprocessor directives also.

AlgorithmLibraryWrapper.hpp:10:1: unterminated #ifdef
AlgorithmLibraryWrapper.hpp:7:1: unterminated #ifndef

I am using the poor vxWorks gcc compiler. Please let me know if the fault is mine or the compiler's.


Solution

  • It could be that the problem is in the included files (if there actually are unbalaced #if/#endifs.

    I would try preprocessing with another compiler. You can use gcc for that, doesn't matter it wouldn't compile. Just get gcc (or MinGW if you're on Windows) and run

    cpp -Iinclude_direcories your_file
    

    Or, if you don't like gcc, get MSVC Express edition. Again, you can preprocess code that even doesn't compile, so no problem with nonworking library etc.

    Most compilers have an option that will give you the output from the preprocessor so you can check what it's doing. For example,

    gcc -E file.c >file.preproc
    

    will give you the pre-processed source so you can check the balancing of #if against #endif.