This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

global variable/MULTIPLE PUBLIC DEFINITIONS

Hi,
I've split my project into files.
I've defined some global variables in one of the header files as follows:

unsigned char ToneDisp[16] = {'D','1','2','3','4','5','6','7','8','9','0',0x2A,0x23,'A','B','C'};
struct channel xdata Ch[16];
unsigned char CHANNELTYPE[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

These variables are used in other files too.

Compiling the files individually everything goes fine while building the project results in:
*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS

How can I avoid this?
Shouldn't I 've defined the global variable that way??

Thanks for your attention in advance
A.E.

Parents
  • no 'mistakes, of a variable defined as twi different things can occur

    Perhaps, but lots of "didn't correctly #define, lots of multiple definition" mistakes can occur -- as is the original poster's problem.

    The preprocessor is ugly enough that it's not worth introducing merely to avoid two different definitions. Also, your interface should not change so often that it's really a problem. Even if you need to make a global variable part of the interface to a module, once you choose to do so, that decision is fixed. You shouldn't be updating the definition all the time, any more than you would gratuitiously rename a function constantly.

Reply
  • no 'mistakes, of a variable defined as twi different things can occur

    Perhaps, but lots of "didn't correctly #define, lots of multiple definition" mistakes can occur -- as is the original poster's problem.

    The preprocessor is ugly enough that it's not worth introducing merely to avoid two different definitions. Also, your interface should not change so often that it's really a problem. Even if you need to make a global variable part of the interface to a module, once you choose to do so, that decision is fixed. You shouldn't be updating the definition all the time, any more than you would gratuitiously rename a function constantly.

Children
  • Also, your interface should not change so often that it's really a problem. Even if you need to make a global variable part of the interface to a module, once you choose to do so, that decision is fixed. You shouldn't be updating the definition all the time, any more than you would gratuitiously rename a function constantly.

    When making several 'somewhat similar' projects you do everything stated above that you "do not do" after each 'steal' from the previous project.

    I would, somewhat, agree with Drew if everything you made was started from scratch, but how often do you do that?

    Erik