Jump to content

Recommended Posts

Posted (edited)

hello, i have to fight with some basic things...

 

I want to work with shared variables in booth Functions...seq.c and app.c

as example:
 u8 PageFirst = 50;
 

so what i found out:

declare it in app.c > seq.c will not recognize it. (as extern u8, or only u8 > don’t matter)

declare it in seq.c > app.c will not recognize it. (as exetrn u8, or only u8 > don’t matter)

declare and initialize it in app.h  as u8 PageFirst = 50; wont work

 

declare it in app.h as u8 PageFirst; works

but i have to initialize it anywhere separate like:

void APP_Init(void){PageFirst = 50;}

and that i dont like... is there a other way?
 

Edited by Phatline
Posted

Ok, here is a simple example:

1) define the variable in exactly one module (e.g. in this case "hardware.c") file

u8 led_startstop = 14;

2) declare the variable as "extern" for use in the corresponding header (e.g. in this case "hardware.h") included by other modules (other .c files)

extern u8 led_startstop;

 

Now you can use the variable in the original c file, as well as in all other .c files, that include the header.

Good luck and many greets!

Peter

Posted (edited)

And your " u8 led_startstop = 14; " must be outside of any function.  If it was inside a function then it can only be found and used by that function.

Edited by kpete
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...