connection between variables in different files

Dear Sir

i want to use with variables that defined at the main, at the file of functions.
i try to add extern to the variables, but it send me an error massege like: non address/-constant initializer.

when i added the sign "()" after the name of the variables i accept an error massege like: error L102: external attribute mismatch

and

error L118: reference made to erroneous external

how can i correct in

thank you

Parents
  • This is bog-standard 'C'; nothing specific to Keil at all - so see any 'C' textbook.

    Basically you must have exactly one definition for each & every identifier;
    You may have as many 'extern' declarations as you like.

    file.c
    // definitions
    char tom = 0; // definition with initialisation
    int  ***;
    long harry;
    file.h
    // declarations
    extern char tom; // NO initialisation!!
    extern int  ***;
    extern long harry;
    #include file.h in any file that needs access to the variables.

    If you also #include file.h in file.c, you will get an error message if they ever get out of step - a good check!

Reply
  • This is bog-standard 'C'; nothing specific to Keil at all - so see any 'C' textbook.

    Basically you must have exactly one definition for each & every identifier;
    You may have as many 'extern' declarations as you like.

    file.c
    // definitions
    char tom = 0; // definition with initialisation
    int  ***;
    long harry;
    file.h
    // declarations
    extern char tom; // NO initialisation!!
    extern int  ***;
    extern long harry;
    #include file.h in any file that needs access to the variables.

    If you also #include file.h in file.c, you will get an error message if they ever get out of step - a good check!

Children
More questions in this forum