delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/02/19:17:56

From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Big Programs
Date: Wed, 02 Apr 1997 22:23:39 GMT
Organization: Oxford University
Lines: 60
Message-ID: <3342d882.1756002@news.easynet.co.uk>
References: <19970328233735555 DOT AAA189 AT ns1 DOT megsinet DOT net>
NNTP-Posting-Host: foot.easynet.co.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Fri, 28 Mar 1997 23:37:36 GMT, admcs AT megsinet DOT net (Paul Schmidt)
wrote:

>I have a game source file that is really big and I would like to split it up
>into multiple files...how would I do this?

There are several reasons why you might want to do this. If you are
irritated at the length of time it takes to compile, splitting it up
will help because unmodified source files don't need recompiling all
the time. If you are finding it difficult to locate sections of code
in your program, splitting it into separate source files with
different types of code in each file will help. Using C++ will also
help here, of course.

As for how to split the program up, I tend to write sevaral different
source files (.c or .cc), each #including any system headers they
require, and a header file for each which prototypes any functions
other source files will need to use. Then each source file also
#includes its own header file and the header files of any other source
files which define functions it needs, as I mentioned above.

This isn't necessarily the most efficient way, but it is very easy to
do and makes it simple to locate any code you need to alter.

As an example, look at the following short program:

--- mainprog.c ---
>#include <stdio.h>
>#include "other.h"
>
>int main(void)
>{
> printf("This is in mainprog.c\n");
> other_print_function();
> printf("This is back in mainprog.c\n");
> return 0;
>}
--- other.c ---
>
>#include <stdio.h>
>
>void other_print_function(void)
>{
> printf("This is in other.c\n");
>}
--- other.h ---
>
>void other_print_function(void);

Strip the leading '>' symbols, of course :) 

To build this program you can use a makefile (for which read the docs
on the make utility) or RHIDE (in which case it's as simple as putting
both .c files into the same project and hitting F9).

I haven't tested this, but it ought to work and I'm tired and I'm
going to bed ;)

-- 
George Foot

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019