[Top][All Lists]
[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 20:43:12 +0200 |
User-agent: |
KMail/1.8 |
Hi,
On Monday 12 September 2005 19:33, Vincent Trouilliez wrote:
> Thanks Till, I tried that, but the compiler complains that my lcd.c (not
> 'foo', but lcd.. ;-) uses undeclared functions and defines, despite in
> main.c (let's call the main C source file this way, I took care to
> include my lcd.h statement UNDER all other usual includes.
So it complains about things missing in lcd.c? Where are these things actually
located? In main.c? In theory you'd then have to write a main.h containing
the prototypes of all parts of main.c you are intending to use in ldc.c.
BUT: You're probably starting to write ugly code! Try to think in hierarchies:
There's main.c. It uses routines from lcd.c and therefore includes lcd.h.
lcd.c may then again use routines from charset.c or i2c.c (if e.g. your
display is attached via i2c) and includes charset.h and i2c.h. If there are
routines back in main that are used in main.c _and_ and lcd.c, then you might
either move them to lcd.c as well (since they are lcd related) or to a
seperate file, because they have a seperate purpose like e.g. some fancy port
access routines. There's usually no need for "circular" includes.
> main.c :
> -------
> #include <stdio.h>
> #include <stdlib.h>
> #include <avr/io.h>
> #include <avr/interrupt.h>
> #include <avr/signal.h>
> #include <avr/delay.h>
>
> #include "lcd.h" <----------- my file with LCD related routines
> (well, only the prototyptes of course)
This is exaclty how it should be.
> Am I supposed to copy all the "regular" includes at the top of lcd.h as
> well ?
Uhm, if there's stuff in lcd.c that uses some of the avr library
functionality: Yes, of course. For the compiler your lcd.c is a completely
seperate thing. You'll have to include all the system headers you are using.
But do you really need all the system includes in main.c anymore? It's a good
habit to check every now and then if your file really needs all these
includes. Removing unused includes speeds up compilation but more important
it makes your code more readable. If i see the "#include <avr/interrupt.h>"
in your main.c, i'd assume that you have placed interrupt routines in main.c,
which may not be true anymore, since you removed some of your code from
there.
Till
--
Dr.Ing. Till Harbaum, address@hidden
- [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Andy Warner, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Francisco Silva, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?,
Till Harbaum <=
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Message not available
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Joerg Wunsch, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Message not available
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, David Kelly, 2005/09/12
- Re: [avr-chat] HowTo split a program into several files ?, Joerg Wunsch, 2005/09/13
- Re: [avr-chat] HowTo split a program into several files ?, Vincent Trouilliez, 2005/09/13
- Re: [avr-chat] HowTo split a program into several files ?, Joerg Wunsch, 2005/09/13