Hello everyone,
I would like to use a global variable that would be visible in all the code, do you know in which file I should define my variable?
JP7NJT
Global var
Re: Global var
The code is partially modular and you don't normally expect to have variables that every single function has access to.
Most variables are declared as static to individual files, to deliberately limit their scope.
This is normal / good programming practice, to limit variability scope.
If you need a variable that is visible to every function, you will probably need to making a new .c file and a new .h and then include that new .h in every file that needs access to your 'global' variable
Re: Global var
Hello, thanks for you reply.VK3KYY wrote: ↑Fri Dec 08, 2023 2:02 amThe code is partially modular and you don't normally expect to have variables that every single function has access to.
Most variables are declared as static to individual files, to deliberately limit their scope.
This is normal / good programming practice, to limit variability scope.
If you need a variable that is visible to every function, you will probably need to making a new .c file and a new .h and then include that new .h in every file that needs access to your 'global' variable
I tried to create a global variable in a .h file.
It works when I include this variable in a single.c file but in multiple file, there is errors :
On the other hand, if I add the variable in static then I can put it in as many.c files as I want.application/include/globalvar.h:2: first defined here.
But I want a volatile variable, not a static variable. I see that there are these kinds of variables like for example uiDataGlobal.Scan. which is visible in all .c files. How do you create this kind of variable?
Re: Global var
This a C language programming question not specific to the firmware. You should post it to a C language programming forum.JP7NJT wrote: ↑Mon Dec 11, 2023 10:27 pmHello, thanks for you reply.VK3KYY wrote: ↑Fri Dec 08, 2023 2:02 amThe code is partially modular and you don't normally expect to have variables that every single function has access to.
Most variables are declared as static to individual files, to deliberately limit their scope.
This is normal / good programming practice, to limit variability scope.
If you need a variable that is visible to every function, you will probably need to making a new .c file and a new .h and then include that new .h in every file that needs access to your 'global' variable
I tried to create a global variable in a .h file.
It works when I include this variable in a single.c file but in multiple file, there is errors :On the other hand, if I add the variable in static then I can put it in as many.c files as I want.application/include/globalvar.h:2: first defined here.
But I want a volatile variable, not a static variable. I see that there are these kinds of variables like for example uiDataGlobal.Scan. which is visible in all .c files. How do you create this kind of variable?