简体   繁体   中英

using local variable of one program as global variable of another c program

want to write two c programs. I want to use the value of the local variable of 1st c program(.c file) in my 2nd c program(.c file) also. How can I use the local variable of one program as global variables of another program? That means how can I make those local variables global so that I can use it in another file. Note that I have only 2 files both are .c files(suppose file1.c, file2.c). write a simple program for me to make local variable of one file to global variable of another file.

I want to put the variable inside the main function (int main()) in one program and these variables will work as a global variable in another program.

There is no standard way to do this, because two processes are separate entities that do not share anything with each other.

However there are techniques ( IPC , short for interprocess communication) that allow for processes to share memory and/or communicate with each other. This techniques however are not part of the Standard C Library and are dependent on the operating system, Windows, Linux, Mac will give you different options.

For linux and unix base systems in general there are for example: shared memory , sockets( native BSD sockets, network sockets, unix sockets, file sockets, pipes, etc), 0mq, etc.

I'm afraid your question is just too broad and every IPC option is different from the other and has up- and downsides. This cannot be answered broadly here, you have to be more specific here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM