473,386 Members | 1,795 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,386 software developers and data experts.

share a variable across two libraries

Hi,
I have to share a variable across two libraries. These libraries are
build separately and share a common header file.

I had tried this earlier using extern variable. That didn't help.

Any ideas about this ??

Thanks and Regards,
Jun 27 '08 #1
2 2271
guddu said:
Hi,
I have to share a variable across two libraries. These libraries are
build separately and share a common header file.

I had tried this earlier using extern variable. That didn't help.

Any ideas about this ??
If you must do this (rather than use parameter-passing, say), do it like
this:

/* commonheader.h */
#ifndef H_COMMONHEADER
#define H_COMMONHEADER 1
extern int shared_object; /* a declaration - include as appropriate */
/* + whatever else you feel appropriate in here */
#endif

/* firstlibsourcefile.c */
#include "commonheader.h"
int shared_object; /* ONE definition, here ONLY */
/* functions and stuff go here */

/* someotherlibsourcefile.c */
#include "commonheader.h" /* get the declaration */
/* Note the absence of a definition */
/* functions and stuff go here */

HTH. HAND.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #2
On Jun 24, 4:14 pm, guddu <visha...@gmail.comwrote:
Hi,
I have to share a variable across two libraries. These libraries are
build separately and share a common header file.

I had tried this earlier using extern variable. That didn't help.
How it didn't help?
Any ideas about this ??
If you want to share data, use parameters. Globals are not a good idea
except in very specific situations. Nevertheless, it works.
Jun 27 '08 #3

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

Similar topics

7
by: George Hester | last post by:
In one Application (2) the client is redirected to a Logon ASP in a different Application (1). A Session Variable is made in Application 2 which needs to be recognized in Application 1. Can I do...
0
by: TaeHo Yoo | last post by:
Hi all, We have three web based applications (A, B and C) and they are kept on different source safe database say SourceSafeA, SourceSafeB and SourceSafeC respectively. A solution contains aa...
5
by: Rich | last post by:
Hi there, For a quite big application, I need to get large amount of data within a static library (xxx.lib) and put them in a database (a class, say we call it CData), and then make it...
8
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to...
2
by: Ahmed | last post by:
Dear All, I have three web applications that I want to provide one single web interface to all of them. If I am able to share the session between them, It will be great. so is this possibel?
11
by: Charles Law | last post by:
I have just been asked how to share functions and properties between two running applications. For example, I have App1 and App2 both running on the same machine. App1 uses a DLL (perhaps) that...
5
by: newjazzharmony | last post by:
I want to share one instance of an object across an ASP dot net application, and I'm trying to weigh the pros and cons of the following two approaches: a) Storing the object in ApplicationState...
3
by: Samuel R. Neff | last post by:
Is there any way to declare a static variable within a generic type definition and have that variable be shared across all constructed generic types? For example, how can I modify this code: ...
6
by: gara.matt | last post by:
Hi, I was wondering, I've been reading some C++ code written by others, usually libraries and stuff, and I've come across what strikes me as a distinctive style that pervades most of the code...
1
by: guddu | last post by:
Hi, I have to share a variable across two libraries. These libraries are build separately and share a common header file. I had tried this earlier using extern variable. That didn't help. Any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...

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.