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.

TMS320F2800157: How to generate a preprocessor macro for filename

Part Number: TMS320F2800157


We'd like to use just the filename in our logs rather than the entire filepath as provided by __FILE__. With GCC we can do:

#define __FNAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)

How can we accomplish similar using the C28X compiler for C2000?

  • Hello Dan,

    I was able to build a project with this macro without an issue, was there a specific error you were getting or was the program not using this macro as expected when you ran it?

    Best regards,

    Omer Amir

  • I'm seeing:

    "../empty_driverlib_main.c", line 208: warning #225-D: function "__builtin_strrchr" declared implicitly

  • Hello Dan,

    Can you show me the section of code where it's being used? That way I can try to replicate it on my side.

    Best regards,

    Omer Amir

  • There's not much to it

        #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
    
        printf("FILENAME: %s\r\n", __FILENAME__);
        printf("FILE: %s\r\n", __FILE__);

    And the error

    **** Build of configuration CPU1_LAUNCHXL_FLASH for project empty_driverlib_project ****
    
    "C:\\ti\\ccs1240\\ccs\\utils\\bin\\gmake" -k -j 12 all -O 
     
    Building file: "../empty_driverlib_main.c"
    Invoking: C2000 Compiler
    
    ...
    
    "../empty_driverlib_main.c", line 212: warning #225-D: function "__builtin_strrchr" declared implicitly
    "../empty_driverlib_main.c", line 212: warning #43-D: operand types are incompatible ("int" and "char *")
    Finished building: "../empty_driverlib_main.c"

  • Hi Dan,

    When I tried using the macro like you showed, there was no builtin_strrchr function. What header file did you include this from? I used stdio.h and string.h, but I could not find what header file has this exact function name (I used strchr and it built without a problem). You can do CTRL+Click on the function name to see where it's being called from, if you don't know offhand.

    Best regards,

    Omer Amir

  • Yes, I agree this builtin function doesn't appear to exist in the C2000 compiler. This is a function provided by gcc, and is not being included from any header. I don't necessarily need this exact function, I just need a way to get the preprocessor to generate filenames to use in our logs. 

  • Hi Dan,

    Can you instead try using the alternate versions of functions that are provided by TI or generic libraries/headers that are provided by CCS? Let me know if you have problems with this.

    Best regards,

    Omer Amir

  • Yes, I'm fine using alternatives, but I'm not sure what they are. Can you please point me to them?

  • Hello Dan,

    These are the two similar-looking functions I found in string.h:

    Best regards,

    Omer Amir