How Do I ......????
Kurt Wall
kwall
Sat Oct 9 06:45:36 PDT 2004
On Thu, Sep 09, 2004 at 02:08:49PM -0500, Ben Duncan took 69 lines to write:
>
> Ok, I am writing a system that contains several modules.
>
> The header for the system has a declaration for a function defined
> as :
>
> int OpenWindow( int row, int col, int rowsize, int colsize, const char
> *title)
>
> row, col, rowsize, colsize are USED thru out all the modules.
>
> I have one program called slag-module.c, that forms the library core
> and calls all other modules compiled in. Some of the modules are
> called : grid.c, button.c, form.c, checkbox.c, ..etc..etc..
They each include the header, right?
> So, I have a compile statement that looks like thus:
> ------------------------------------------------------
> for file in `ls src/*.c`
> do
> OBJ=`basename $file ".c"`
> echo "Now creating file $OBJ from $file "
> cc -c -O2 -fno-strength-reduce " objdir/${OBJ}.o \
> -I./include -I/usr/include/slang \
> -fwritable-strings \
> src/${OBJ}.c
> done
That's certainly doing it the hard way. Make is your friend:
OBJS := grid.o button.o form.o checkbox.o
CFLAGS := -O2 -fno-strength-reduce -fwritable-strings
INCLUDES := -I./include -I/usr/include/slang
.c.o:
$(CC) -c $(CFLAGS) $(INCLUDES) -o objdir/$@ $<
> echo "Now creating the .so module"
> cc -c -02 -fno-strength-reduce -shared -fPIC \
> -I./include -I/usr/include/slang src/slag-module.c \
> objdir/*.o \
> -o objdir/slag-module.so \
> -L/usr/lib -lslang -ldl -lm
> --------------------------------------------------------
>
> In the slag-module.c is the actual OpenWindow function, and
> in several of the c program modules they call
> OpenWindow( 'int row', 'int col', 'int rowsize', 'int colsize', "String
> of data")
Why not just use a proper function? And why are are you specifying
multi-character char types?
OpenWindow(1, 2, 3, 4, "some string");
> What I would like to do is set up some sort of GLOBAL variable, so that the
> modules that are using "OpenWindow" would do it this way:
>
> gl_row = 'int row' ;
> gl_col = 'int col' ;
> gl_rowsize = 'int rowsize' ;
> gl_colsize = 'int colzise' ;
>
> OpenWindow( "string of data")
>
> An where "gl_xxxxx" is modifiable from any modules, they are
> defined JUST in one place.
You just write a wrapper around OpenWindow() that calls it the way you
want it called:
OpenWindowWrapper(const char *s)
{
OpenWindow(row_val, col_val, rowsize_val, colsize_val, s);
}
More generally, unless I'm missing something, it is unwise program design
to do what you're proposing. It defeats type checking and makes your code
a lot harder to read. Those global variables can get changed by anything
in scope, which introduces some nasty bugs.
> So, how do I set this up do to this ?
Kurt
--
No man in the world has more courage than the man who can stop after
eating one peanut.
-- Channing Pollock
More information about the Linux-users
mailing list