same name global variable multi-files



Hi,

I used to have different c code in different files and compiled as
different programs. For example, I have

proc1.c:

int x1, x2;

void work1()
{
int b = x1 + x2;
...
}

x1 and x2 are global variables and proc1.c and other c files are
compiled as to a program called "p1".


proc2.c:

int x1, x2;

void work2()
{
int b = x1 * x2;
...
}

proc2.c and other c files are compiled to a program called "p2".

I am now working on a new program where I would like to have both
function "work1" and "work2". I tried to share the same code but it did
not link because x1 and x2 has the same name in proc1 and proc2. Since
proc1 and proc2 have many many global variable with the same names and
I have even proc3, proc4...., I do not want to change them one by one.
Is there a good way to solve the naming conflict? Since I still use the
code in my separated program p1 and p2, I would like to keep the change
as little as possible. I do not want to put proc.1 into a c++ class,
for example.

Thanks,
qq

.



Relevant Pages

  • [PATCH 1/13] kconfig/lxdialog: refactor color support
    ... In the process introduced a global variable named 'dlg' which is ... Global variables ... -extern int parse_rc; ... void init_dialog; ...
    (Linux-Kernel)
  • Re: global variables
    ... require global variables ... int foreach(const void *elt), ...
    (comp.programming)
  • Re: same name global variable multi-file
    ... int x1, x2; ... void work1() ... x1 and x2 are global variables and proc1.c and other c files are ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • same name global variable multi-file
    ... int x1, x2; ... void work1() ... x1 and x2 are global variables and proc1.c and other c files are ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)