This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

error: identifier "class" is undefined

Other Parts Discussed in Thread: MSP430FR5739, MSP430WARE

I also posted this on MSP430 Forum, but so far no response, but I have following output 

error: identifier "class" is undefined

So far I tried everything, including renaming main.c to main.cpp and in 

Project => options => Build => MSP430 Compiler => Advanced Options => Language Options => Treat C files as C++ file

My target is MSP430FR5939, and I am using free version of CCS5.  Does free version support C++?  We are considering switching to this hot new controller, but I cant get started with it, do I need to buy CCS seat or is this CCS bug?  Am I doing something wrong.  Below is the listing of the class, it chokes on "class"

class CharQueue
{
private:
void start_pp(); // incruments start pointer
void end_pp(); // incruments end pointer
// shoudl be private
unsigned int start; // First character in buffer
unsigned int end; // Next open Character Character in buffer
unsigned char buffer[BUFF_LEN];

public:
CharQueue(); // constructor
int enqueue(unsigned char data[], int data_length); // add string to stack
int enqueue(unsigned char); // add char to stack - overloaded
int buffer_size(); // returns true if stack is not empty
char dequeue_char(); // deque char from stack (DISABLES INTERRUPTS)
};

  • Except for no definition of BUFF_LEN, that is legal C++ code.  

    Please show the entire contents of the Console window after you try to build this file.

    Thanks and regards,

    -George

  • Here is another listing:

    **** Build of configuration Debug for project PressureSensor ****

    "C:\\ti\\ccsv5\\utils\\bin\\gmake" -k all
    making ../src/grace/grace.lib ...
    cle430X InterruptVectors_init.c ...
    "C:/ti/ccsv5/tools/compiler/msp430_4.1.3/bin/cl430" --abi=eabi -c --obj_directory=objs/ -vmspx --near_data=none --code_model=large --data_model=restricted --symdebug:dwarf --optimize_with_debug -qq -pdsw225 -D__MSP430FR5739__ -I "C:/ti/ccsv5/tools/compiler/msp430_4.1.3/include" -I "C:/ti/grace_2_00_01_65/packages" -I "C:/ti/ccsv5/ccs_base/msp430/include" -I "C:/ti/ccsv5/ccs_base/msp430/MSP430ware_1_30_00_15/packages/../" "InterruptVectors_init.c"
    "c:/Working/PressureSensor/CharQue.h", line 23: error: identifier "class" is undefined
    "c:/Working/PressureSensor/CharQue.h", line 23: error: expected a ";"

    >> Compilation failure
    "c:/Working/PressureSensor/CharQue.h", line 38: warning: parsing restarts here after previous syntax error
    2 errors detected in the compilation of "InterruptVectors_init.c".
    gmake[1]: *** [objs/InterruptVectors_init.obj] Error 1
    gmake[1]: Target `all' not remade because of errors.
    gmake: *** [../src/grace/grace.lib] Error 2
    'Building file: ../main.cpp'
    'Invoking: MSP430 Compiler'
    "C:/ti/ccsv5/tools/compiler/msp430_4.1.3/bin/cl430" -vmspx --abi=eabi -g --include_path="C:/ti/ccsv5/ccs_base/msp430/include" --include_path="C:/ti/ccsv5/tools/compiler/msp430_4.1.3/include" --include_path="C:/ti/ccsv5/ccs_base/msp430/MSP430ware_1_30_00_15" --advice:power=all --define=__MSP430FR5739__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp" --cmd_file="./configPkg/compiler.opt" "../main.cpp"
    "../main.cpp", line 24: warning #112-D: statement is unreachable
    'Finished building: ../main.cpp'
    ' '
    gmake: Target `all' not remade because of errors.

    **** Build Finished ****

  • I do not see the option  --cpp_default (also known as -fg) anywhere on that compile step command line.

  • OK, here is the problem, this is the Grace Project, and she is written in C.  I am trying to call a class member function from Grace ISR and that is where the problem begins.  If I do not call the class member from Grace I get no errors.  Not sure what to do about it yet.

  • So far, if I move the InterruptVectors_init.c to the user source directory and rename it to .cpp, it all works, but  Grace snippets do not work in the InterruptVectors_init.cpp file, have to use the actual address locations.  This breaks Grace and easy ability to reconfigure, so is there a clean way to work it out preserving Grace files?  I am angry with Grace, she wasted my whole day:(

  • You should probably leave InterruptVectors_init.c as a C file, and have it call only C or 'extern "C"' functions. If you must call a C++ function, make an 'extern "C"' wrapper (defined in the C++ file) which calls it.

  • How would I do that?  I need to wrap into C the following function of the class:

    void CharQue::enqueue(unsigned char)

    so if I instantiate:

    CharQue txBuffer;

    How do I get the pointer to the function CharQue.enqueue()?

    So in my CharQue.cpp, i should have

    extern "C" int enqueue(unsigned char rx, &txBuffer){

         txBuffer->enqueue(rx);

    }

    Does that look right?

  • You're probably going to want to define txBuffer in the CPP file rather than have it as a parameter to the 'extern "C"' function.  Try:

    cfile.c

    extern int enqueue(unsigned char);

    cppfile.cpp

    CharQue txBuffer;
    extern "C" int enqueue(unsigned char rx) {
      txBUffer.enqueue(rx);
    }
  • Archaeologist,

    I did lots of research as well and worked out a solution, but your solution is simpler then mine, why did I not think of it? I guess my mind does not work as well on Fridays.  So here is what I did.

    code in .h but the class has to be wrapped in #ifdef __cplusplus #endif or compiler will bark at you.

    #ifdef __cplusplus
    extern "C" {
    #endif
    int enqueue(void *, unsigned char); // takes pointer to object CharQue and character to enque

    char dequeue(void * ); // takes Pointer to Object #ifdef __cplusplus
    }
    #endif

    Code in .cpp class implimenation file

    extern "C"{
    int enqueue(void *object, unsigned char data){ return ((CharQue*)object)->enqueue(&data, 1); }
    char dequeue(void *object){ return ((CharQue*)object)->dequeue_char(); }
    }

    in cpp that instantiates CharQue

    CharQue txCellBuffer; // Cell comm buffer
    void * txCell = &txCellBuffer;

    in InterruptVectors_init.c

    #include "CharQue.h"

    extern void * txCell;

    enqueue(txCell, UCA0TXBUF) 

    The disadvantage of my approach is it is more complex, the advantage is it is more modular and the function abstracts the class.

  • I recommend that TI wraps function prototypes inside eaurt.h and the rest of the  files in driverlibs with

    #ifdef __cplusplus
    extern "C" {
    #endif

    #ifdef __cplusplus
    }
    #endif

  • Those files are not products of the compiler group.  You'd be better off making this suggestion in a forum which supports that library.  I'm sorry, I don't know who produces it.

  • Who produces the MSP430Ware?  I would post it there.

  • The best place is the MSP430 forum.

    Thanks and regards,

    -George