Skip to main content
Bumped by Community user
added 4 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 17

global Global variables with c++C++ in multiuplemultiple files

I'm not a c++C++ programmer  (but I have used regular cC code for implementing low level-level machine language equivalent SW for some time), and after tyingtrying to modify an existing c++cC+ program to do what I need (and failing), I've decided to rewrite parts of the code in plain cC code.

But to be able to use the data, I need to create some variables that have to be accessableaccessible to parts of the existing c++C++ code.

When I declare a global variable (extern int variable name;extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.

I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?

global variables with c++ in multiuple files

I'm not a c++ programmer(but have used regular c code for implementing low level machine language equivalent SW for some time), and after tying to modify an existing c++ program to do what I need (and failing), I've decided to rewrite parts of the code in plain c code.

But to be able to use the data, I need to create some variables that have to be accessable to parts of the existing c++ code.

When I declare a global variable (extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.

I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?

Global variables with C++ in multiple files

I'm not a C++ programmer  (but I have used regular C code for implementing low-level machine language equivalent SW for some time), and after trying to modify an existing cC+ program to do what I need (and failing), I've decided to rewrite parts of the code in plain C code.

But to be able to use the data, I need to create some variables that have to be accessible to parts of the existing C++ code.

When I declare a global variable (extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.

I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?

Source Link
user29356
  • 89
  • 1
  • 3
  • 9

global variables with c++ in multiuple files

I'm not a c++ programmer(but have used regular c code for implementing low level machine language equivalent SW for some time), and after tying to modify an existing c++ program to do what I need (and failing), I've decided to rewrite parts of the code in plain c code.

But to be able to use the data, I need to create some variables that have to be accessable to parts of the existing c++ code.

When I declare a global variable (extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.

I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?