473,467 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

about common variable

I have define a MACRO varible as a common variable that be refered by
several classes.

#ifndef COMMON_VAR
#define COMMON_VAR 1

....

#endif

Whenever I want to change the value of common_var, I only need to
redefine it at the beginning of the source code. However, I am going
to compile all the classes into a library. That is, my code must link
to the library before I can use the classes. I found that redefine
the COMMON_VAR will no longer work because the classes has already
been compiled into a static library. How can I overcome this problem?
Jul 19 '05 #1
2 2130
WW
Rex_chaos wrote:
I have define a MACRO varible as a common variable that be refered by
several classes.
There is not such thing as a "marco variable". It is a macro.
#ifndef COMMON_VAR
#define COMMON_VAR 1

...

#endif

Whenever I want to change the value of common_var, I only need to
redefine it at the beginning of the source code. However, I am going
to compile all the classes into a library. That is, my code must link
to the library before I can use the classes. I found that redefine
the COMMON_VAR will no longer work because the classes has already
been compiled into a static library. How can I overcome this problem?


You will need to use something else, not a macro. What do you want to do
exactly?

--
WW aka Attila
Jul 19 '05 #2
"Rex_chaos" <re*******@21cn.com> wrote...
I have define a MACRO varible as a common variable that be refered by
several classes.
There is no such thing as "MACRO varible". It's a macro. Nothing
variable about it.

#ifndef COMMON_VAR
#define COMMON_VAR 1

...

#endif

Whenever I want to change the value of common_var, I only need to
redefine it at the beginning of the source code. However, I am going
to compile all the classes into a library. That is, my code must link
to the library before I can use the classes.
"Compile classes into a library" and "code must link to the library"
are two different concepts. They cannot be connected with "that is".
I found that redefine
the COMMON_VAR will no longer work because the classes has already
been compiled into a static library. How can I overcome this problem?


Drop a macro and use a variable. Make it 'extern' if you expect
the users of your library to be able to change its value.

Read about "extern" linkage specifier in your favourite C++ book.

Victor

Jul 19 '05 #3

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
15
by: Simon Harvey | last post by:
Hi everyone, I am fairly new to learning about xsl and xml, but one thing I have noticed is that anyone offering a tutorial or lesson on it seems to think that its the most incredible invention...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
34
by: wilson | last post by:
Hi All, I am a novice at C and just have learned pointer for a short period. Today one error had occured while executing my program below. And I cannot find the error out since it's checked "OK"...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
0
by: Henry | last post by:
Using ideas provided by some of you I was able to figure out how to get the names of the parameters fields of a crystal report specified at run time. The code below just basically puts the...
2
by: qiooeer | last post by:
I want to know more about FSM,would you help me ? where is more details about this? Thanks
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
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,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.