Phatline Posted January 27, 2016 Posted January 27, 2016 (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 January 27, 2016 by Phatline
Hawkeye Posted January 28, 2016 Posted January 28, 2016 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
kpete Posted January 29, 2016 Posted January 29, 2016 (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 January 29, 2016 by kpete 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now