P
Peter Ammon
I would like to share a variable between two functions defined in two
separate source files; no other functions will need the global variable
so I'd prefer to not give it file scope. Thus, I want a variable with
local scope, external linkage, and static storage.
I believe I can do this for the file that does not define the variable
by declaring it inside a function. Can I also avoid giving it file
scope in the file that does define the variable?
/* File 1 */
void function1(void) {
/* How do I make myGlobal have static storage,
* and external linkage?
*/
int myGlobal;
}
/* File 2 */
void function2(void) {
/* This does what I think it does, right? */
extern int myGlobal;
}
Thanks for your help,
-Peter
separate source files; no other functions will need the global variable
so I'd prefer to not give it file scope. Thus, I want a variable with
local scope, external linkage, and static storage.
I believe I can do this for the file that does not define the variable
by declaring it inside a function. Can I also avoid giving it file
scope in the file that does define the variable?
/* File 1 */
void function1(void) {
/* How do I make myGlobal have static storage,
* and external linkage?
*/
int myGlobal;
}
/* File 2 */
void function2(void) {
/* This does what I think it does, right? */
extern int myGlobal;
}
Thanks for your help,
-Peter