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.

CODECOMPOSER: What the low level logic on TI ARM CLANG when compiler process the macro defintion

Part Number: CODECOMPOSER

Tool/software:

Hi Compiler experts,

I have below question on TI ARM CLANG Complier.

Refer below examples:

A.h files:
#define TEST 1

B.h files:
#ifndef TEST
    #define TEST 2
#endif

There has two files give the same macro definition, I want to know how the compiler process these macro definition:

I am concerning whether there has the risk that sometimes it will process the B.h files at first, then it will define twice and make the error occur.

Meanwhile, the second question is that, what the marco definition difference between the pre-definition in project property and manually define it in main.c files?

Looking forward to your feedback.

B.R.

Sal

  • Hello,

    Here are the answers:

    1. The order in which the macros are processed is completely dependent on the order in which the header files are included. For example, if a .h or .c file has the following lines, the macros in a.h will be processed first.

    #include "a.h"

    #include "b.h"

    2. These are just 2 approaches to defining macros. Adding the macro in the project property provides the flexibility of changing the macros at build without having to change the source.

    Ajay

  • Hi Ajay,

    Thanks for clarification.

    For question 2, then what is the order of the pre-definition and souce code macro definition?

    Which one has the highest order when it comes to souce code compiler?

    B.R.

    Sal

  • Macros defined on the tiarmclang command line (via -D) are processed first. Note that if you define the same macro on the command line and in your source, the compiler will emit a macro redefinition warning.