[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Best practice for external variable (newbie-ish quest
From: |
David Kelly |
Subject: |
Re: [avr-gcc-list] Best practice for external variable (newbie-ish question) |
Date: |
Sun, 20 Nov 2005 19:00:36 -0600 |
On Nov 20, 2005, at 1:16 AM, Joerg Wunsch wrote:
As Russell already mentioned, the best way to maintain that is by
placing a single declaration of the variable into a central header
file that is included from all source files.
Or in the event all the functions that need to access the global
variable are in the same source file just drop the whole "extern"
thing and simply declare the variable outside of a function before
its first use. Then don't bother to restate it as "extern" inside a
function because as you have already demonstrated that method is
prone to error, and because the function already knows about that
variable.
The only time I use "extern" is for prototyping in #include files.
Even so, the variable has to be declared somewhere without "extern"
and outside of a function in order to create the allocation. Make
sure you #include the prototype file in the source file which creates
the storage for the variable because avr-gcc will bellyache if the
two do not match. This is one of the ways one makes the compiler
double-check one's work.
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.
- [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/19
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Russell Shaw, 2005/11/19
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Russell Shaw, 2005/11/19
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question),
David Kelly <=
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), David Kelly, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/20
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/21
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Matthew Smith, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Joerg Wunsch, 2005/11/22
- Re: [avr-gcc-list] Best practice for external variable (newbie-ish question), Russell Shaw, 2005/11/20