473,503 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#include

Hello Everybody,

I have a main program and I would like to include another program
(MN.h) inside my main program. I already know how to use "extern"
for the variables that I have defined as int, double ... in my main
program to use the information of my main program in the program that I
want to include in my main program however I have some variables that I
have used "#define" in my main program but I don't know how I
should use extern for the variable which I have used "#define" for
them. For example in the follwing main program I know how to use extern
to define "int AS" and "int AD" and I have shown how I have
used extern in the other program but I don't know how to use extern
for "M" and "R".
Is there anybody to tell me how I can do that?
Thanks,

MY MAIN PROGRAM:

#include <stdio.h>
#include <stdlib.h>
#include "MN.h"

#define M
#define R

int AS;
int AD;
..
..
..
..
MN.h program that I want to include:

#include <stdio.h>
#include <stdlib.h>

extern int AS;
extern int AD;
..
..
..
..
..

Jul 5 '06 #1
4 1224
Mohsen wrote:
Hello Everybody,

I have a main program and I would like to include another program
(MN.h) inside my main program. I already know how to use "extern"
for the variables that I have defined as int, double ... in my main
program to use the information of my main program in the program that I
want to include in my main program however I have some variables that I
have used "#define" in my main program but I don't know how I
should use extern for the variable which I have used "#define" for
them. For example in the follwing main program I know how to use extern
to define "int AS" and "int AD" and I have shown how I have
used extern in the other program but I don't know how to use extern
for "M" and "R".
You can't. A macro's scope only extends to the current compilation unit.

Why would you want to use macros for variables?

--
Ian Collins.
Jul 5 '06 #2
Dear Ian,
My main program produces some files which are going to be used in the
"MN.h" program. In order to define those files for the "MN.h", the
"MN.h" needs to know about "M" and "R" but I don't know how to tell the
"MN.h" about them.
Thanks,
Mohsen

Ian Collins wrote:
Mohsen wrote:
Hello Everybody,

I have a main program and I would like to include another program
(MN.h) inside my main program. I already know how to use "extern"
for the variables that I have defined as int, double ... in my main
program to use the information of my main program in the program that I
want to include in my main program however I have some variables that I
have used "#define" in my main program but I don't know how I
should use extern for the variable which I have used "#define" for
them. For example in the follwing main program I know how to use extern
to define "int AS" and "int AD" and I have shown how I have
used extern in the other program but I don't know how to use extern
for "M" and "R".

You can't. A macro's scope only extends to the current compilation unit.

Why would you want to use macros for variables?

--
Ian Collins.
Jul 5 '06 #3
Mohsen wrote:
Dear Ian,

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the newsgroup FAQ:

<http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4>


Brian
Jul 5 '06 #4
Mohsen wrote:

Top posting corrected.
Ian Collins wrote:
>>Mohsen wrote:
>>>Hello Everybody,

I have a main program and I would like to include another program
(MN.h) inside my main program. I already know how to use "extern"
for the variables that I have defined as int, double ... in my main
program to use the information of my main program in the program that I
want to include in my main program however I have some variables that I
have used "#define" in my main program but I don't know how I
should use extern for the variable which I have used "#define" for
them. For example in the follwing main program I know how to use extern
to define "int AS" and "int AD" and I have shown how I have
used extern in the other program but I don't know how to use extern
for "M" and "R".

You can't. A macro's scope only extends to the current compilation unit.

Why would you want to use macros for variables?
Dear Ian,
My main program produces some files which are going to be used in the
"MN.h" program. In order to define those files for the "MN.h", the
"MN.h" needs to know about "M" and "R" but I don't know how to tell the
"MN.h" about them.
A .h file is a header. If you wish to share a variable in one source
module with another, declare it as extern in a header file to be
included by both source files and define it exactly once in one of them.

--
Ian Collins.
Jul 5 '06 #5

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

Similar topics

43
5042
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
6075
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
60
8210
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
9
6397
by: zolli | last post by:
Hi, I've been banging my head against this for a while now. Hoping someone here can shed some light on what's going on. On including stdlib.h in a file, I'm seeing the following errors: ...
5
2495
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
1
7457
by: Minh | last post by:
I've just installed VS.NET 2003 on my Athlon XP 1800+. However I couldn't get any project with STL includes to compile even if I create a new empty project (and added #include <string>). It gave me...
1
4543
by: ya man | last post by:
when i use #include <iostream.h> in some files i get lots of error messages of the kind 'ambiguous symbol this is solved when i use #include <iostream why is that ? and can i use #include...
3
2690
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
14
6671
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
7
2894
by: Giancarlo Bassi | last post by:
Please, what are here the 11 include files (found over the internet)? */mozzarella.c /* #include #include #include #include #include #include
0
7205
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
7093
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
7353
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
7468
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...
1
5023
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
4689
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
3180
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...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
401
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...

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.