473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

sharing variables across mulitple files

I have a set of variables that I want to share across mulitple c++
files. I was using the extern method so far. Is there any other way to
do the same. The variables are not constants and I get the values
during run time.
Jun 27 '08 #1
6 1708
aw********@gmail.com wrote:
I have a set of variables that I want to share across mulitple c++
files. I was using the extern method so far. Is there any other way to
do the same. The variables are not constants and I get the values
during run time.
extern is the way you do it normally, other than passing the variables as
parameters.

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #2
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>
extern is the way you do it normally, other than passing the variables as
parameters.

--
Jim Langston
tazmas...@rocketmail.com
thanks for the reply. yes i should have also mentioned that i did not
want to pass the variables all the time. the reason i am looking for
alternate ways is after learning that memory for global variables is
reserved in the heap and a lot of global variables can create problems
for a program.

Jun 27 '08 #3
On 2008-05-06 06:26:32 -0400, "aw********@gmail.com"
<aw********@gmail.comsaid:
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>>
extern is the way you do it normally, other than passing the variables as
parameters.

--
Jim Langston
tazmas...@rocketmail.com

thanks for the reply. yes i should have also mentioned that i did not
want to pass the variables all the time. the reason i am looking for
alternate ways is after learning that memory for global variables is
reserved in the heap
Not usually. They go in the same memory area as static data.
and a lot of global variables can create problems
for a program.
Well, as far as memory usage, maybe. But more important is that they
introduce sneak paths for data modification, which can make program
analysis and maintenance harder. Sometimes sharing is unavoidable, of
course.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Jun 27 '08 #4
Pete Becker wrote:
On 2008-05-06 06:26:32 -0400, "aw********@gmail.com"
<aw********@gmail.comsaid:
>On May 6, 3:07 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>>>
extern is the way you do it normally, other than passing the
variables as parameters.

--
Jim Langston
tazmas...@rocketmail.com

thanks for the reply. yes i should have also mentioned that i did not
want to pass the variables all the time. the reason i am looking for
alternate ways is after learning that memory for global variables is
reserved in the heap

Not usually. They go in the same memory area as static data.
> and a lot of global variables can create problems
for a program.

Well, as far as memory usage, maybe. But more important is that they
introduce sneak paths for data modification, which can make program
analysis and maintenance harder. Sometimes sharing is unavoidable, of
course.
I have one project where I am forces to use global variables because of the
engine I am using having multiple callbbacks and it's impossible for me to
pass the data. One thing I did was I put all the global variables in a
structure and have just one instance of the structure. I'm not sure if it
simplifies anything, but it helps.

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #5
On May 6, 5:50 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
Pete Becker wrote:
On 2008-05-06 06:26:32 -0400, "awhan.i...@gmail.com"
<awhan.i...@gmail.comsaid:
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
>extern is the way you do it normally, other than passing the
variables as parameters.
>--
Jim Langston
tazmas...@rocketmail.com
thanks for the reply. yes i should have also mentioned that i did not
want to pass the variables all the time. the reason i am looking for
alternate ways is after learning that memory for global variables is
reserved in the heap
Not usually. They go in the same memory area as static data.
and a lot of global variables can create problems
for a program.
Well, as far as memory usage, maybe. But more important is that they
introduce sneak paths for data modification, which can make program
analysis and maintenance harder. Sometimes sharing is unavoidable, of
course.

I have one project where I am forces to use global variables because of the
engine I am using having multiple callbbacks and it's impossible for me to
pass the data. One thing I did was I put all the global variables in a
structure and have just one instance of the structure. I'm not sure if it
simplifies anything, but it helps.

--
Jim Langston
tazmas...@rocketmail.com
the structure idea is actually novel. how about if u just include the
prog that has the variables defined in them, and call a function from
the new one to the old one?
will that work?
Jun 27 '08 #6
Jim Langston wrote:
I have one project where I am forces to use global variables because of
the engine I am using having multiple callbbacks and it's impossible for
me to
pass the data. One thing I did was I put all the global variables in a
structure and have just one instance of the structure. I'm not sure if it
simplifies anything, but it helps.
Sounds like a very bad C callback mechanism. It is a "C" callback mechanism
because otherwise it would have allowed generic functors and full compile
time type checking on the given functions and arguments. It is a "bad C
callback mechanism" because otherwise it would take in one form or another
an opaque argument (usually under the form of a "void*" argument) to
register along with the callback and that value is passed back to the
callback, the argument usually being used to transmit state from the code
registering the callback to the callback.

Yeah, organizing the data to be shared in a struct may help (it is usually
required with the "void*" passing method described above).

--
Dizzy

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex | last post by:
Hi all, I want to write a "File sharing system". Is posssible with socket and thread create multisuer connection at the same time ? or is wrong my idea?? thanks
1
by: Simon Neve | last post by:
Hello, This question is related to sharing .Net projects across solutions and is reposted from the SourceSafe group. We have several different solutions and want to share common assemblies...
2
by: PeteZ | last post by:
Hi, I was of the understanding that Session variables were GLOBALLY scoped across all Applications on a specific web site and that data obtained and stored in "variables" were available for...
4
by: Cowboy \(Gregory A. Beamer\) | last post by:
Background: ------------- The idea started as a single sign on type of application. Having tested it before, I knew we could institute single sign on using the same Authentication Cookie name (in...
3
by: Shikari Shambu | last post by:
Hi All, I have a situation where multiple applications are sharing some pages/ controls. So, I have a separate common project that has the common pages/ controls. My question is how do I...
4
by: W Akthar | last post by:
Hi, I need to pass session state variables across different web applications. Firstly is this possible and secondly can someone show me how please??
1
by: Terry Olsen | last post by:
What is the best practice for sharing variables across modules in the same project? I'm doing a console app with different modules for different functions (file i/o, sql commands, string...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
2
by: Jeff Dege | last post by:
I'm working with a group that's been doing C++ coding for quite a long time, now, and in that environment we've pretty much worked out development practices that serve us well. We've been doing...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.