473,657 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1726
aw********@gmai l.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*******@rocke tmail.com
Jun 27 '08 #2
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
>
extern is the way you do it normally, other than passing the variables as
parameters.

--
Jim Langston
tazmas...@rocke tmail.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********@gma il.com"
<aw********@gma il.comsaid:
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
>>
extern is the way you do it normally, other than passing the variables as
parameters.

--
Jim Langston
tazmas...@rock etmail.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********@gma il.com"
<aw********@gma il.comsaid:
>On May 6, 3:07 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
>>>
extern is the way you do it normally, other than passing the
variables as parameters.

--
Jim Langston
tazmas...@roc ketmail.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*******@rocke tmail.com
Jun 27 '08 #5
On May 6, 5:50 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
Pete Becker wrote:
On 2008-05-06 06:26:32 -0400, "awhan.i...@gma il.com"
<awhan.i...@gma il.comsaid:
On May 6, 3:07 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
>extern is the way you do it normally, other than passing the
variables as parameters.
>--
Jim Langston
tazmas...@rock etmail.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...@rocke tmail.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
2781
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
1944
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 across them. Is it best to share the project and its files to each solution (each solution has it's own shared project), or have each solution point to the same file location of the project?
2
1368
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 other applications - it seems I was wrong. It appears that the data is held on a per-application instance ie. Each applications data is "sand-boxed" from other apps and cannot be referenced.
4
2046
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 this case "AuthenticationCookie" -- yeah, original, I know) and the same machine keys for the applications. <authentication mode="Forms"> <forms name="AuthenticationCookie" path="/" loginUrl="login.aspx" protection="All" timeout="10" />
3
2786
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 reference these pages/ controls from my ASP.NET web projects WEbApp1 url http://localhost/app1 C:\Apps\App1
4
1349
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
1596
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 manipulation, etc). But I have variables in the main module that other modules need to access such as AppPath, etc. What is the "best practice" concerning a situation like this?
5
11811
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 $MYVAR, $a; ?>
2
1967
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 more and more, over the last few years, in C# and ASP.NET. Some web apps, some background services. In our C++ code base, we have a fair number of statically-linked libraries that contain code we share between projects. At this point, in our...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.