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.

overriding redeclaration of a variable in application

i have created a static variable called memlen in a library decoder.pjt in a header file called typedefs.h.

since it is included many times in the project; it creates more than one instances of memlen.

the same file is included in application.pjt also...

sow to overcome this problem to have only one instance of variable

  • A typical practice to use is to cradle the variables, typedefs, etc. in a header file with the following construct.

    #ifndef TYPEDEFS_H
    #define TYPEDEFS_H

    <your stuff normally in typedefs.h>

    #endif

  • Declare your variable in the C source file where you want to use it rather than in that header file.  As you have discovered, declaring the variable in the header file creates multiple instances of the variable.  If you want to have a variable declared in a library but globally accessible then you should declare the variable in the source file and extern the variable in the header file.

  • I am new to CCS v4, but when I try to declare my global variables in a global_vars.h file, CCS complains about expecting a "{" right before the first extern variable.

    This same syntx worked in IAR. Am I missing something silly? Error is at the line withthe first "extern"

    #ifndef

     

     

    extern unsigned char TXByteCtr;
    extern unsigned char RXByteCtr;
    extern unsigned char TXData;
    extern unsigned char RXData;
    extern unsigned char TestData;
    ...

    GLOBAL_EXTERNS_H
    #define GLOBAL_EXTERNS_H
  • for some reason the post messed up text, but it originally looked like this:
    (here's hoping it takes it this time)

    #ifndef GLOBAL_EXTERNS_H
    #define
    GLOBAL_EXTERNS_H

     

     

    extern unsigned char TXByteCtr;
    extern unsigned char
    RXByteCtr;
    extern
    unsigned char
    TXData;
    extern
    unsigned char
    RXData;
    extern
    unsigned char
    TestData;
    ...
  • Please ignore this. Just a forgotten ";" not flagged in a previous file and me getting used to CCS error messages. :-(