|
From: Keith M. <kei...@us...> - 2006-05-17 23:29:14
|
On Wednesday 17 May 2006 8:00 pm, Michael Gerdau wrote: > > A cleaner approach [in Steve Pribyl's opinion] would be. > > I challenge that this is cleaner -- in particular for larger projects > your suggestions easily gets out of hand. Or that's my experience. > > > utils.h > > extern FILE *system_log_file; > > > > utils.c > > FILE *system_log_file; > > > > No messy cpp code. > > Messy ?!? > We will to disagree on that one. Well, FWIW I too would do just as Steve suggests, except that in utils.c I would initialise system_log_file: #include "utils.h" : FILE *system_log_file = NULL; which is then consistent with the OP's example. Also, if this were in a sizeable project, I'd probably put utils.o into a project local library, for convenience in managing the build. And yes, for this type of initialisation, C *is* less messy than C++ IMO, simply because C++ is complete overkill. The caveat is that utils.h needs to make the declaration conditionally `extern "C"', if the project includes C++ modules which will use it, and, of course if utils.c needed to define some objects for which C++ would be more appropriate than C, then I would replace it with utils.cpp. > Anyway, your proposal spreads definition and declaration across > two files which is inferior in this regard. Eh???? It's completely standard practice to separate declarations and definitions in this manner; *.h files *should* have declarations *only*, while definitions go in *,c or *.cpp files. Unless you never use header files, then *you* must do this all the time. Regards, Keith. |