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.
Why not use one header file for all globally used variables and/or functions? Correct me if this is not what you meant.
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.
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.
Thanks guys. I didn't know about extern definitions when I asked this. I'm back on track now. :P