This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ucos ii and c++ compiler

Hello,
I'm trying to move a c project in c++. I just tried to change extension to main.c to main.cpp but I get an error including ucos_ii.h at OsTaskCreateExt and I cannot find what i going wrong with the function declaration.
Can anyone help me?
Thanks
Michele

Parents
  • Hi,
    I'm back at work. That's the error I get when I compile my main.cpp

    compiling main.cpp...
    ..\Src\.\rtos\ucos_ii.h(752): error: expected an expression
    ..\Src\.\rtos\ucos_ii.h(752): error: expression must have (pointer-to-) function type
    ..\Src\.\rtos\ucos_ii.h(752): error: type name is not allowed
    ..\Src\.\rtos\ucos_ii.h(752): error: identifier "pd" is undefined
    ..\Src\.\rtos\ucos_ii.h(752): error: expected a ")"

    and that is line 752 of ucos_ii.h

    INT8U OSTaskCreateExt(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt);

    As I said before, the header should be c++ compliant.
    I tried to comment the first declaration "void (*task)(void *pd)," so it seems there is something wrong in it.
    Thanks very much for your help
    michele

Reply
  • Hi,
    I'm back at work. That's the error I get when I compile my main.cpp

    compiling main.cpp...
    ..\Src\.\rtos\ucos_ii.h(752): error: expected an expression
    ..\Src\.\rtos\ucos_ii.h(752): error: expression must have (pointer-to-) function type
    ..\Src\.\rtos\ucos_ii.h(752): error: type name is not allowed
    ..\Src\.\rtos\ucos_ii.h(752): error: identifier "pd" is undefined
    ..\Src\.\rtos\ucos_ii.h(752): error: expected a ")"

    and that is line 752 of ucos_ii.h

    INT8U OSTaskCreateExt(void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt);

    As I said before, the header should be c++ compliant.
    I tried to comment the first declaration "void (*task)(void *pd)," so it seems there is something wrong in it.
    Thanks very much for your help
    michele

Children
  • Thank you very much for your help

    I wrote your declaration in my .h file and the compiler passes it fine.

  • Perhaps the compiler is confused by the pointer-to-function as an argument? You can try and verify this by trying to compile a simplified version of the declaration:

    int func(void (*fptr)(void *ptr));
    


    See if the compiler chokes on this. If it does, it will be a bug in the compiler, I think...

  • I tried to change the function declaration from

    OSTaskCreateExt(void (*task)(void *pd), ..

    to

    OSTaskCreateExt(void (*INT16U)(void *pd), ...

    Can it be that "task" is not declared? Doesn't it know what it is? I searched in ucos ii .h files and I cannot find a declaration for "task".

  • "Can it be that "task" is not declared?"

    In a function pointer theclaration:

    STaskCreateExt(void (*task)(void *pd), ..
    


    "task" is just an arbitrary name for this parameter, just as:

    int sum(int a,int b);
    


    the parameter names a and b are arbitrary names.

    It will not be problematic unless "task" is a reserved keyword, or possibly the name of a data type.

  • that's line 752

    #if OS_TASK_CREATE_EXT_EN > 0

    I did that
    #ifdef __cplusplus
    INT8U OSTaskCreateExt(void (*INT16U)(void *pd),
    #else
    INT8U OSTaskCreateExt(void (*task)(void *pd),
    #endif

    and it compiles.
    I tried the modification in my c project and I downloaded the firmware on my board and it works .. but I don't like to just trick the code without understanding why it works.
    Thanks very much for your help

  • I wrote your declaration in my .h file and the compiler passes it fine

    Then it must be something above line 752. Often you get compiler errors on lines following the line which actually causes problems.
    The error messages 'expected an expression' and 'expression must have (pointer-to-) function type' might mean that the compiler thinks that it is processing the body of a function.
    Perhaps it would be a good idea to post some code preceeding line 752 here.

  • As I said, changing "task" to INT16U it compiles .. but I still have a linker problem

    *** ERROR L127: UNRESOLVED EXTERNAL SYMBOL SYMBOL: _main MODULE: ..\Obj\main.obj (MAIN)
    *** ERROR L128: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: _main MODULE: ..\Obj\main.obj (MAIN) ADDRESS: A60DH
    *** ERROR L128: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: _main MODULE: ..\Obj\main.obj (MAIN) ADDRESS: A60EH

    Do you have any suggestion? The main is declared in main.cpp as int main(void){ .. }

  • That's what I wrote in my main.cpp

    and that's waht I found checking the main.ic

    int main(void)
    { INT8U ucErr; static INT16U sdata Ram_test_result = 0; static INT16U sdata led_blink = 0; static INT16U sdata led_switch = 0;

    #define LED_TIMEOUT 40000

    //SignInit(); P7_P7 = 0; //disable bypass scr CC1_SEE = 0x0000; //disabilita gli out-compare CC1_OUT_CC6IO = 0; //disable input scr R P1L_P0 = 0; //disable input scr T P1L_P1 = 0; //disable input scr S P9_P5 = 0; //disable battery+ scr P1L_P7 = 0;

    #line 549
    int main(void)
    {

    static INT16U sdata Ram_test_result = 0U;
    static INT16U sdata led_blink = 0U;
    static INT16U sdata led_switch = 0U;
    #line 551
    auto INT8U ucErr;
    #line 550
    _main();
    #line 559
    P7_P7 = 0U;
    CC1_SEE = ((unsigned int)0U);
    CC1_OUT_CC6IO = 0U;

    .. it seems it add a call to function _main() and that is the error I get.

  • I defined just one main in my main.cpp and than I found that the compiler has added, as I showed, a _main(); function call in my main().

    Maybe there is something wrong in my main declaration. Should I have to do something different?

    I cannot understand your comment. Again, thank oyu very much, this c++ conversion is far more difficult that I was expected it would be .. and i'm just changing main.c in .cpp .. there are a lot of files to be converted! :(

  • Standard C/C++ rule. Your C library expects a C main. Most c++ compilers manages this themselves, but try with extern "C" main, to make sure that the external symbol will be named _main.

    /pwm

  • A C function named _main() will have an external binding __main (i.e. two underscores).

    A C++ function named _main() may have just about any strange name, that somewhere constains the _main sub-string.

  • Searching "_main" in keil help I found that the c++ keil compiler (EC++) requires to call the _main() function at the beginning of the main() function.
    This function mainly contains new/delete functions for C++ operator new/delete.