472,973 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

#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 1207
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
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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.