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.

Variadic macros in CCS compiler

We are currently compiling C code for an ARM Cortex m3 system. It is indicated that the variadic macros require a --gcc compiler switch and we keep getting an error on variadic macros. It seems that the compiler doesn't recognize the macros. Is there any way to do reconfiguration in Code Composer Studio so that variadic macros get working?

 

  • If you are using ARM tools v4.4.0 or newer varadic macros should work.  If they do not it is probably a compiler bug.  Can you give an example of what is not working?

     

  • The macro is defined in this way:

    78 #if D >= 1

    79    #define DEBUG(str,arg...)   function("AAA"str, f(),##args);

    80 #else

    81    #define DEBUG(str,arg...)   {}

    82 #endif

     

    This is within .h file and the error report says on line 81

    expected a ")"

     

    This shows the macro isn't working.

    We have made sure there is not mistake in the code.

  • I assume it a simple typo in your message that  you say "##args" instead of "##arg" or you would have worse problems.

    Using compilers 4.4.0 or newer your example compiles correctly for me.  However, if I use a compiler older than that I see the same error that you are seeing.  I think it is quite likely you are using compiler with a lower version number than 4.4.0.  Note that the version number that matters here is that of the Code Generation Tools, not that of Code Composer Studio.

    There are probably better ways within CCS to find the tool version, but you can get it to display by using the -version option when compiling.

     

  • Sorry for the typo. Your assumption is right.

    As to the compiler version, I have difficulty looking for it. Because everything in the CCS was automatically installed what I did was no more than click the icon starting the IDE.

    Is it necessary to find the directory of compiler program and run the command line (I am in Windows environment) to check the version?

  • You should be able to check from within CCS.  I think there is a place in the menus for entering compiler options where  you can type any string you want (although the string is checked for validity).  Enter "-version" there and compile.

    There are easier and more preferred ways to do this in CCS.  If you can wait until tomorrow (US) someone reading this can tell you the right way to find the compiler version number from within CCS.

     

  • Thank you very much for your help. I am ready for more technical guide tomorrow.

  • To find the version of compiler tools being used in CCS:

    - if using CCS 3.3, go to Help->About. The version of code generation tools should be listed there
    - if using CCS4.x, right click on the project, go to Properties->CCS Build, the code generation tools version should be listed in the Project Settings

  • I am using CCS v5.1 and I check the compiler version under project property. It shows the compiler version is TI v4.9.1

    It now seems strange why the macro doesn't work when I clicked "build all". Is there any other configuration I missed?

  • http://processors.wiki.ti.com/index.php/Code_Generation_Tools_FAQ#Q:_Does_the_TI_compiler_support_variadic_macros.3F

    I did read the above wiki link learning Variadic macros are not well supported in TI comiler unless a -gcc compiler switch is used.

    Could anyone tell me what this means? How do I use a --gcc compiler switch?

  • Hi everyone,

    I try define the Variadic macros as below

    #define   LOG(x, arg...)    printf(x, arg...)

    but error message was obtained:

    expected a ")"

    How I can solve this problem?

    Thanks!

    CCSv4.2, C6000

  • Remove the second "...".  Write it like this

    #define LOG(x, arg...) printf(x, arg)

    Thanks and regards,

    -George

  • Hi,

    But when I try doing as you said, then obtain errors again.

    #include <stdio.h>

    #define LOG(x, arg...) printf(x, arg) 

    void testMacros( int arg )

    {

        LOG("acbdef");

        LOG("acbdef %d", arg);

    }

    "../variadic.c", line 2: error: expected a ")"
    "../variadic.c", line 5: error: too few arguments in macro invocation
    "../variadic.c", line 5: error: expected an expression
    "../variadic.c", line 6: error: expected an expression
    4 errors detected in the compilation of "../variadic.c".

  • This wiki article about GCC extensions in TI compilers includes links to the GCC documentation for each extension.  The GCC documentation for variadic macros leads to rewriting your macro like this ...

    #define LOG(x, ...) printf(x, ## __VA_ARGS__)
    // changes       ^^^          ^^^^^^^^^^^^^^

    Now it builds clean with both gcc and cl470 --gcc.
    Thanks and regards,
    -George

  • I have a related question. 

    The variadic macro seems to work for the simple case like above, but I am getting errors when I used this (found in http://en.wikipedia.org/wiki/Variadic_macro):

    #define MYLOG(FormatLiteral, ...)  fprintf (stderr, "%s(%u): " FormatLiteral "\n", __FILE__, __LINE__, ##__VA_ARGS__)

    
    
    I use C6000 7.4.2.

    Thanks,
    tamo2

  • I don't get any errors when I use that macro.  Please send in a complete test case that I can build.  Include the exact compiler options you use.

    Thanks and regards,

    -George

  • Hi George, 

    Thanks for the quick response.

    Here you go:

    #include <stdio.h>
    #define MYLOG(FormatLiteral, ...)  fprintf (stderr, "%s(%u): " FormatLiteral "\n", __FILE__, __LINE__, ##__VA_ARGS__)
    void test()
    {
      MYLOG("test\n");
    }

    Build result:

    "C:\\ti\\ccsv5\\utils\\bin\\gmake" -k -j 4 all
    'Building file: C:/SL/trunk/workspace_3000_win/tmp.cpp'
    'Invoking: C6000 Compiler'
    "C:/ti/ccsv5/tools/compiler/c6000_7.4.2/bin/cl6x" -mv6600 --abi=eabi -Ooff -g --include_path="C:/ti/ccsv5/tools/compiler/c6000_7.4.2/include" --include_path="C:/ti/bios_6_35_01_29/packages/ti/bios/include" --display_error_number --diag_warning=225 --diag_wrap=off --preproc_with_compile --preproc_dependency="tmp.pp" --cmd_file="./configPkg/compiler.opt" "C:/SL/trunk/workspace_3000_win/tmp.cpp"
    "C:/SL/trunk/workspace_3000_win/tmp.cpp", line 2: error #41: expected an identifier
    "C:/SL/trunk/workspace_3000_win/tmp.cpp", line 5: error #20: identifier "__VA_ARGS__" is undefined
    2 errors detected in the compilation of "C:/SL/trunk/workspace_3000_win/tmp.cpp".

    >> Compilation failure
    gmake: *** [tmp.obj] Error 1
    gmake: Target `all' not remade because of errors.

  • You need to add the build option --gcc.  That's because you are using an extension to the C/C++ language that is borrowed from the GCC compiler.

    Thanks and regards,

    -George

  • George Mock said:
    You need to add the build option --gcc.  

    It did the trick!

    Thanks!