Declaration problem with Global C Variable


I have developed a project including a number of C and Assebly files and functions. When I define a global variable in one of the C file (i.e main.c) and want to use it in another C file (i.e. interrupts.c), I got a compilation error "[Error(ccom)] unknown variable". I am using Renesas HEW and my project is to develop code for MC16C/62P family. The compiler is "M16C Series, R8C Family C Compiler V.5.45 Release 01 (Update Utility) (5-8-2012 13:37:23)".

I appreciate if anyone may help me for this issue to fix.



  • Hi,

    I assume you use the extern keyword (in interrupts.c or interrupts.h) to reference the global variable in main.c?


  • Hi,

    Yes I have used extern myVar in interrupts.c but I found why I got that error, I defined the myVar variable as static, so it means that I can not use it by another file.

    Please comment.



  • Any variable that is changed inside an interrupt needs to be declared volatile.

    For example:


    extern volatile myVar;  // provides access to variable inside main


    volatile myVar; // it lets the program know that the interrupt can modify this value anytime