1 |
On 7/6/06, Iain Buchanan <iaindb@××××××××××××.au> wrote: |
2 |
> yes I would, except that I'm editing a class which is inherited by a |
3 |
> multitude of programs, so the /proc way I only have to change one file, |
4 |
> whereas the argv[0] way I have to change every source file... |
5 |
|
6 |
No, that's the point of a global. Inheritance and all doesn't matter. |
7 |
|
8 |
You change main.c (2 lines): |
9 |
char* progname = 0; |
10 |
... |
11 |
progname = argv[0]; |
12 |
|
13 |
main.h (1 line): |
14 |
extern char* progname; |
15 |
|
16 |
and the source file where you want to use it it (2 lines): |
17 |
#include "main.h" |
18 |
... |
19 |
printf("progname is %s\n", progname); |
20 |
|
21 |
Your details might vary, for example if there is already a globals.h |
22 |
you could move the declaration from main.h to there, etc. But this |
23 |
really is the sane way of doing this... |
24 |
|
25 |
-Richard |
26 |
-- |
27 |
gentoo-user@g.o mailing list |