Public Group

Archived

This topic is now archived and is closed to further replies.

This topic is 5987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Im trying to break apart some of my code into seperate header and c files to make it a little more readable. But im have some difficulties with it. How is the best way to break things up? (Right now im trying to model after the circlemud code. ie i have a structs file and a comm file [this is were the directx goes.] ) Also does the include go into the header file or the c file? ie main.c main.h? Any help would be appreciated. Ive been trying to mess clean this up for the last couple days and im just getting frustrated. Thanks in advance Bryan

Share on other sites
Andrew throws a link at Lethian with this!

Share on other sites
very good andrew, but if you actually went to that website and read it you might have noticed that it doesn''t mention this topic.
Lethian: header files have the class/function declarations in them, and the source (.c or .cpp) files have the implementation. the header files are included in any source files that need to use those functions:
// blah.hint someFunc(char*);// blah.c#include "blah.h"int someFunc(char* daParam)  {  // whatever...  return 4;  };

now, to use someFunc() in another source file (let''s say main.c) just include blah.h in that source file. basically, when the headers are included the compiler actually inserts that header file into the code at that point, so putting #include "blah.h" at the top of main.c is the same as just declaring the someFunc function prototype there (but with fewer keystrokes, and in a safer manner).
hope that helps.

--- krez (krezisback@aol.com)

Share on other sites
It does a help a bit. What im having trouble with. (Hopefully i can expalin this.)

Here are my .c files
main.c
comm.c

here are my .h files
main.h
comm.h
structs.h

now in structs.h i am defining a structure PLAYER_INFORMATION. Then in comm.h I create an array variable of type PLAYER_INFORMATION.
PLAYER_INFORMATION playerinfo[MAX_PLAYERS];

Now i have structs included in both main.h and comm.h (i also have the define preprocessor so it wont be defined again) but i get a missing storage-class or type specifier error when i compile. I am assuming this is because for whatever reason its not getting that PLAYER_INFORMATION has been defined and there for cant creat the variable.

Bryan

Share on other sites
Yeah i tried extern earliar. But it gave me the same error.

Share on other sites
Now do you only use #includes in the .c file or the .h files?

Share on other sites
Well ive gotten closer. Now it runs through the compiler but when it goes to the linker it gives an alread defined error lnk2005. Any ideas?

Share on other sites
Does anyone have a link to a good resource for the usage of extern and code modulization? I have Practical C++ Programming, which is a good book, but the section on extern sucks.

-OOProgrammer
virtual void life() = 0;

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 22
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631733
• Total Posts
3001927
×