This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I pass device information instance from one file to another?

Hi 

I am working with nrf52832 development kit. I am trying to write device information service from central device to peripheral device. 

I am successfully able to write manufacture name if I device information instance, db_descovery_init and device information handler in same file.

Due to my project requirements I had to separate out files, so as per now I have 2 files

I file a.c

Db_descovery_init

And in file b.c

Device information init

Note that I have created my device information instance in file a.c

Now the problem is my device information instance does not pass the same value as I pass through db_descovery_init. Every time in file b.c I got the NULL value of the instance.

I know this may be because of the static declaration of the instance. 

How do I solve this issue? 

I will appreciate your timely help.

Thanks,

KRA

Parents
  • Hi,

    It is not clear to me what you have done. Is the case that you want a global variable that is accessible from two (or more) C files? If so, then you need to declare it normally in one of the files (make sure it is not static). In the other files (or in a .h file that is included in the other files), you declare it in the same way but prefixed with extern. This way you can access the same variable in multiple files.

Reply
  • Hi,

    It is not clear to me what you have done. Is the case that you want a global variable that is accessible from two (or more) C files? If so, then you need to declare it normally in one of the files (make sure it is not static). In the other files (or in a .h file that is included in the other files), you declare it in the same way but prefixed with extern. This way you can access the same variable in multiple files.

Children
No Data
Related