Continue to Site

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 2
Joined
May 17, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,448
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
 

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;

}
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top