By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

#include

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.