• Advertisement

Archived

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

Question about includes

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.h
int 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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;

Share this post


Link to post
Share on other sites

  • Advertisement