Global variable definitions

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
rolfz
Posts: 30
Joined: 08 Jun 2006 23:40
Location: Switzerland

Global variable definitions

#1 Post by rolfz » 16 Jun 2006 15:20

Can anyone help me to understand where I need to put global variables ?

I try to declare simple variable like this transparent to all source code.

int radio_ch[8];
char ch_index;

In a header file I call in main: it works.
Directly in main .c code, I get an error that the variables are undeclared
In header in both .c files I get an error of Identifiers redefined.

So do not realy understand the logic behind. I would expect that a variable not defined within a routine is considered as global.
Thanks for any feedback
Rolfz

rolfz
Posts: 30
Joined: 08 Jun 2006 23:40
Location: Switzerland

#2 Post by rolfz » 19 Jun 2006 21:11

Looks like this was not a successful call for help.

Found the following.

Including strict header file with subroutines and global variables helps.
extern on global variable seems to answer my question

extern int radio_ch[8];
extern int ch_index;

BR
Rolfz

rolfz
Posts: 30
Joined: 08 Jun 2006 23:40
Location: Switzerland

#3 Post by rolfz » 23 Jun 2006 22:23

Thanks to Srdjan

Problem solved,

variable definition in core routine
int radio_ch[8];
int ch_index;

extern definition in all others.
extern int radio_ch[8];
extern int ch_index;

many thanks
Rolfz

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”