avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] global variables - avr-gcc


From: Richard Urwin
Subject: Re: [avr-chat] global variables - avr-gcc
Date: Sun, 21 Aug 2005 10:43:59 +0100
User-agent: KMail/1.7.2

On Sunday 21 Aug 2005 08:49, Tomas Krcka wrote:
> Hi!
>    I have a problem with global variables -  avr-gcc compiler.
>
> The problem is:
>
> I have file system.c
>        byte proc_tbl[MAX_PROCESS];  //it's global variable in
> system.c void System_Init(void){
>           int i;
>            for (i = 0;i < MAX_PROCESS; i++)
>              proc_tbl[i] = NOT_USED;
>        }
> and function
>
>       byte Create_Process(void){
>            int i;
>            for (i=0; i < MAX_PROCESS; i++)
>               if (proc_tbl[i] == NOT_USED){
>                      proc_tbl[i] = USED;
>                      return(OK);
>               }
>        return(ERROR);
>       }
> It's a simplified example, but doesn't work too.
>
> If I call these functions in main.c
>         System_Init();
>         Create_Process();
>  function Create_Process return ERROR permanently.
>
> If global variable proc_tbl is static, it's work fine.
> And If I change sequence of linking obj files, system.o is first,
> It's work fine too.

You need to declare proc_tbl in all the files that use it. The K&R 
standard is:

in system.o:
   byte proc_tbl[MAX_PROCESS] = {NOT_USED};
in the file containing Create_Process:
   extern byte proc_tbl[MAX_PROCESS];

gcc is rather more relaxed about it, so using:
   byte proc_tbl[MAX_PROCESS];
or maybe
   extern byte proc_tbl[MAX_PROCESS];
everywhere should work.


-- 
Richard Urwin




reply via email to

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