Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP need c guru : extern variable declaration in data.h

Status
Not open for further replies.

coolhand21

Junior Member level 3
Joined
May 17, 2010
Messages
26
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,460
Hi I would like to declare a variable in a data.h and be able to use in other modules.c
--------------------------------------------
data.h
#ifndef _DATA_H_
#define _DATA_H_
int foo = 10;
#endif

--------------------------------------------

#include "data.h"
extern int foo;

void main
{
foo = 12;
test();

}
-------------------------------------------

#include "data.h"
extern int foo;

test()
{
foo = 1+ foo;

}
------------------------------------------
my compiler complains multiple defintions

What i'm I doing wrong
thanks cool
 

blind_man

Member level 3
Joined
Feb 26, 2005
Messages
56
Helped
10
Reputation
20
Reaction score
10
Trophy points
1,288
Location
Romania
Activity points
1,646
data.h
#ifndef _DATA_H_
#define _DATA_H_
extern int foo;
#endif

--------------------------------------------

#include "data.h"
int foo = 10;

void main
{
foo = 12;
test();

}
-------------------------------------------

#include "data.h"
test()
{
foo = 1+ foo;

}
 

g_shyam1682

Full Member level 4
Joined
Jan 11, 2010
Messages
206
Helped
53
Reputation
106
Reaction score
43
Trophy points
1,308
Location
Udaipur-Rajshan-India
Activity points
2,551
Hi friend

you don't declare variable in Header file
Instead of
you can do this

--------------------------------------------

int foo = 10;

void main
{
foo = 12;
test();

}
-------------------------------------------
extern int foo;

test()
{
foo = 1+ foo;

}

Best of Luck
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top