avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] (no subject)


From: Dave Hylands
Subject: Re: [avr-gcc-list] (no subject)
Date: Mon, 30 Jan 2006 11:29:45 -0800

Hi,

Sending to list...

> I live a problem with avr gcc: When i use a global variable in the header
> file and simultaneously initialize it to nonzero value in the declaration,
> then the use of this header file in multiple project source files as an
> include causes "multiple definition error" on this specific lines in the
> header file. Not initialized globals (by myself) and defines do not cause
> any error.  the whole header file content  is in a conditional define, in a
> regular manner, so  i dont understand what is going on. what is wrong?

In the header file, you need to use the word extern.

Putting:

   int x;

says to allocate storage for an int sized variable named x. Since this
is in a header file, every C file that includes the header file will
try to create a variable named x, which is where the multiple
declarations are coming from.

Using:

   extern int x;

says that somebody else has allocated storage for an int sized variable named x.

--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/




reply via email to

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