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, [EMAIL PROTECTED]
========================================================================
Whom computers would destroy, they must first drive mad.



_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to