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.

CCS/TM4C123GE6PM: Understanding why a variable is invisible in my main.c

Part Number: TM4C123GE6PM


Tool/software: Code Composer Studio

Hello,

I defined a variable inside a .c file as follows:

volatile bool g_bMPU6050Done; // stdbool.h was included.

This file was added to my CCS project.

When I try to use it in one of my functions inside main.c I get the following error:

Description Resource Path Location Type
#20 identifier "g_bMPU6050Done" is undefined

When I move the "volatile bool g_bMPU6050Done;" definition to a different .h file that also added to my project - the build completes without errors.

Why does this happen ?

  • Hello Shai,

    We aren't really a general C code support, and if it's compiler specific question then you should ask CCS forum.

    That said, my hunch on reading this issue is that you need to declare it one place and then make it available to other files via the 'extern' keyword.

    So the source file it is declared would be "volatile bool g_bMPU6050Done;"

    And the other files using it would say "extern volatile bool g_bMPU6050Done;"

    I think that would resolve it, but if not you'll need to check around with either CCS if its compiler specific or general C code forums like stackoverflow.
  • Thanks.
    I posted it on the CCS forum.
    e2e.ti.com/.../738931

    Using "extern" didn't work. And I think it's redundant.
    As far as I know C (unlike C++) treats all variables of an included file as external by default.