Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a static variable (static in module scope) be accessed from another module? In C

Tags:

c

I am not very much familiar with modular structure of C programming, so I decided to ask you for help. Let pretend I have two modules into the project. The one is sx1272.c and the other is sx1272_ll.c. The variable radio_is_on is declared in sx1272_ll.c as follows:

static uint8_t volatile radio_is_on;

and then accessed by function in sx1272.c like this:

foo(){
   ...............
   if(radio_is_on){
      blablabla...
      ............
   }
   ...............
}

So if radio_is_on is static (in module scope) how come it is accessed by other modules?

sx1272_ll.c

sx1272.c

like image 436
Radoslaw Krasimirow Avatar asked Jan 30 '26 12:01

Radoslaw Krasimirow


1 Answers

It seems to me that you included

 #include "sx1272_ll.c"

in you your source file sx1272.c

So the whole content of file sx1272_ll.c is just copy-pasted into sx1272.c, at the position where you have written #include "sx1272_ll.c" during the pre-proccesing stage.

Refer this link: https://en.wikipedia.org/wiki/C_preprocessor#Including_files

like image 136
K.H.A.J.A.S Avatar answered Feb 01 '26 03:02

K.H.A.J.A.S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!