[Top][All Lists]

[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


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.


   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.


   extern int x;

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

Dave Hylands
Vancouver, BC, Canada

reply via email to

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