• Welcome to Valhalla Legends Archive.
 

Organizational Problem?

Started by NicoQwertyu, September 27, 2005, 02:05 PM

Previous topic - Next topic

NicoQwertyu

I don't know how to explain the issue I'm having, but as my projects get slightly bigger, I start splitting certain functions into different files.

For instance:
main.c
chat.c
chat.h
connection.c
connection.h
commands.c
commands.h
fileio.c
fileio.h


The problem occurs when I start needing files to share certain variables (like socket descriptors) and I just start to get very sloppy.  If anyone a little more experienced with c has any tips for organizing my projects better, please help me out.

Yegg

Why not use one header file for all globally used variables and/or functions? Correct me if this is not what you meant.

MyndFyre

You could use structures for things that are common and pass those around.  For example, you might have:
** a HFILE for a log
** a SOCKET for a socket
** a HWND for a rich text box window

All of these objects could be grouped together in a single structure that is used on a per-connection basis:


typedef struct tagConnectionParams {
  int id;
  SOCKET socket;
  HWND hRichTextBoxWnd;
  HFILE hLogFile;
} CONNECTION_PARAMS, *PCONNECTION_PARAMS;


Then you can pass that structure or pointers to it around.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: Yegg on September 27, 2005, 02:19 PM
Why not use one header file for all globally used variables and/or functions? Correct me if this is not what you meant.

Although this would work, I strongly recommend NOT doing this.  When you have a project with dozens or hundreds of source files, it's really annoying to have the whole project rebuild because one declaration in one header changed.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!