avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] HowTo split a program into several files ?


From: Till Harbaum
Subject: Re: [avr-chat] HowTo split a program into several files ?
Date: Mon, 12 Sep 2005 18:37:27 +0200
User-agent: KMail/1.7.2

Hi,

On Monday 12 September 2005 18:10, Vincent Trouilliez wrote:
> Okay I changed the <foo.c> for "foo.c" and the compiler is now
> happy ! :o)
>
> --
> Vince, who can now keep his programs very tidy...
Uhm ... unfortunately noone told you, that this isn't the way to split 
programs ... it works, but it's soooooo ugly.

Header files are not meant to contain code-generating statements, but things 
like prototypes, type definitions, macros etc. In C you therefore there are 
conventions that you place your code in .c files and the no-code-generatinmg 
stuff in .h files (the so called header files) files. And you #include only 
the header files and no .c files.

If you really want your program being split into several parts, you split it 
into several .c source files (seems you are already doing this with your 
foo.c) and then tell the compiler to compile these into one program by either 
first compiling all the source files into seperate object files (.o files) 
and use the linker to link them together to one big program. Or you can tell 
the compiler to directly compile and link seperate source files by just 
feeding them all into gcc at once (gcc -o foo main.c foo.c morefiles.c ...) .

In your example above you'd write a file named foo.h containing prototypes of 
all functions you placed in foo.c and then include foo.h in both, your main 
source file and foo.c (you include foo.h in foo.c to make sure, that the 
compiler complains if you made a mistake writing your prototypes).

Ciao,
  Till

-- 
Dr.-Ing. Till Harbaum                       Tel.:  +49 721 4998963
BeeCon GmbH                                 Fax:   +49 721 4998962
Haid-und-Neu Strasse 7, 76131 Karlsruhe     Mobil: +49 179 9087904
address@hidden                           http://www.beecon.de




reply via email to

[Prev in Thread] Current Thread [Next in Thread]