K
Kevin Joplin
Hi there,
I've almost finished writing simple server application and i have one
little doubt. Suppose we have main server code in server.c file. Rest
of the code we divided into some pices and put into server_2.c,
server_3.c etc. Now we need to share some of the server.c variables
between server_2.c, server_3.c etc. so we put the declaractions of
these variables in server.h with "extern" prefix and include it
(server.h) in rest of the sources. We also put in server.h some consts
describing server, such a port number, version, max lenght of nick
etc. these information are necessary when someone would write a client
application. so in server.h we gathered two types of information :
external declarations for server sources (modules) and const for
future client developers. i used tehnique shown below to separate
these two kinds of adaptation:
in server.h
<cut>
//informations about server
const int SERVER_PORTNUMER = 2003;
const int NICK_LENGHT = 20;
//etc.
#ifdet __SERVER
//for other server modules
extern int iUsers;
//etc.
#endif
<cut>
than i added in makefile : -D__SERVER
all works good but i'm interested what are your opinions about this
tehnique and how you solve similar problems ? is it good idea to keep
two kinds of different information in one header file ? it allow to
gather all stuff in one place. maybe there are some better styles,
maybe you create a few different header files ... pls answer.
thanks in advance.
Kevin
I've almost finished writing simple server application and i have one
little doubt. Suppose we have main server code in server.c file. Rest
of the code we divided into some pices and put into server_2.c,
server_3.c etc. Now we need to share some of the server.c variables
between server_2.c, server_3.c etc. so we put the declaractions of
these variables in server.h with "extern" prefix and include it
(server.h) in rest of the sources. We also put in server.h some consts
describing server, such a port number, version, max lenght of nick
etc. these information are necessary when someone would write a client
application. so in server.h we gathered two types of information :
external declarations for server sources (modules) and const for
future client developers. i used tehnique shown below to separate
these two kinds of adaptation:
in server.h
<cut>
//informations about server
const int SERVER_PORTNUMER = 2003;
const int NICK_LENGHT = 20;
//etc.
#ifdet __SERVER
//for other server modules
extern int iUsers;
//etc.
#endif
<cut>
than i added in makefile : -D__SERVER
all works good but i'm interested what are your opinions about this
tehnique and how you solve similar problems ? is it good idea to keep
two kinds of different information in one header file ? it allow to
gather all stuff in one place. maybe there are some better styles,
maybe you create a few different header files ... pls answer.
thanks in advance.
Kevin