• Not Answered

Compiler/TMS570LS0432: compilation error using macros

Part Number: TMS570LS0432

Tool/software: TI C/C++ Compiler

The following code does not compile using TI ARM compiler v17.3.0.STS or TI v5.2.8.  I have not tried other versions.

// test.c

int getVal(void) { return 0; }

int will_compile(void) { ; int retVal = getVal(); return 0; }

#define MAKE_FUNC( funcName )  int funcName(void) { ; int retVal = getVal(); return 0; }

MAKE_FUNC(wont_compile)

// TI ARM compiler has the following complaints:
//
// >> Compilation failure
// source/subdir_rules.mk:21: recipe for target 'source/test.obj' failed
// "../source/test.c", line 9: warning #994-D: missing return statement at end of non-void function "wont_compile"
// "../source/test.c", line 9: error #68: expected a "}"
// "../source/test.c", line 9: error #60: function call is not allowed in a constant expression
// "../source/test.c", line 9: error #171: expected a declaration
// "../source/test.c", line 9: error #171: expected a declaration
// At end of source: warning #12-D: parsing restarts here after previous syntax error
// 4 errors detected in the compilation of "../source/test.c".
// gmake: *** [source/test.obj] Error 1

Here is the pre-processed output:

int getVal(void) { return 0; }

int will_compile(void) { ; int retVal = getVal(); return 0; }


int wont_compile(void) { ; int retVal = getVal(); return 0; }

The pre-processed output compiles just file if saving it as a .c file.

--thx

test.c:

6735.test.c

test.pp.c:

test.pp.c

Note that the forum interface will not let me upload a ".pp" file, so I have renamed it to a ".pp.c" file, but, other than renaming, that file is exactly as the pre-processor created it.

2 Replies

  • Thank you for notifying us about this problem.  I can reproduce it.  I filed CODEGEN-2259 in the SDOWP system to have this investigated.  You are welcome to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question
    The CCS Youtube Channel
     has short how-to videos
    The 
    Compiler Wiki answers most common questions
    Track an issue with SDOWP. Enter your bug id in the Search box.

  • I believe this is known issue CODEGEN-1979. If your source code has a statement (";") before a declaration ("int retVal = getVal();"), and the declaration does not have white space in front of it, the parser will emit an incorrect error ("error: expected a "}""). When you put code like that into the preprocessor, it strips all whitespace, so even though there actually is a space in the macro, there is no space when the parser gets to work. You'll need to rearrange your macro so that there are no statements before any of the declarations.