470,831 Members | 1,891 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

what will be the value of #define

Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.

Thanking you all

Bye

Mar 2 '07 #1
14 2106
raghu said:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
Your #define doesn't affect any identifier by the name of SYATEM_H -
but, presuming you meant SYSTEM_H, its value prior to the #ifndef
depends on whether it exists. If it didn't, then its value after the
#define (in your example) will be 0.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 2 '07 #2
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
(Just in case it's a trick question): Impossible to tell,
based on the information provided.

(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 2 '07 #3
On 2 Mar, 13:22, Eric Sosman <esos...@acm-dot-org.invalidwrote:
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.

(Just in case it's a trick question): Impossible to tell,
based on the information provided.

(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.
To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
....
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.

Mar 2 '07 #4
Eric Sosman said:
raghu wrote:
>Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.

(Just in case it's a trick question): Impossible to tell,
based on the information provided.

(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.
Ah, good point. I realise now that my parallel reply may seem a little
odd, but of course I was thinking of its value when used in
preprocessor directives such as #if.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 2 '07 #5
On Mar 2, 6:28 pm, mark_blue...@pobox.com wrote:
On 2 Mar, 13:22, Eric Sosman <esos...@acm-dot-org.invalidwrote:
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
(Just in case it's a trick question): Impossible to tell,
based on the information provided.
(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.

To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
...
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.
Yes you are correct. I am imlementing exactly like this but one thing
I didn't understand what will be the value assigned FRED_H here. when
the processor looks in to it their must be change in the value. Right.
what will be that value.

Thanks for ur reply.

Bye

Mar 3 '07 #6
raghu wrote:
On Mar 2, 6:28 pm, mark_blue...@pobox.com wrote:
On 2 Mar, 13:22, Eric Sosman <esos...@acm-dot-org.invalidwrote:
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
(Just in case it's a trick question): Impossible to tell,
based on the information provided.
(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.
To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
...
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.

Yes you are correct. I am imlementing exactly like this but one thing
I didn't understand what will be the value assigned FRED_H here. when
the processor looks in to it their must be change in the value. Right.
what will be that value.

Thanks for ur reply.
No particular value will be assigned. The symbol FRED_H is defined and
will remain defined until explicitly undefined with an #undef
directive. If you want, you can also do:

#ifndef FRED_H
#define FRED_H 1

/* ... */

#endif /* FRED_H */

Mar 3 '07 #7
"raghu" <ra*********@gmail.comwrites:
On Mar 2, 6:28 pm, mark_blue...@pobox.com wrote:
>On 2 Mar, 13:22, Eric Sosman <esos...@acm-dot-org.invalidwrote:
raghu wrote:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
[...]
(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.

To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
...
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.

Yes you are correct. I am imlementing exactly like this but one thing
I didn't understand what will be the value assigned FRED_H here. when
the processor looks in to it their must be change in the value. Right.
what will be that value.

Thanks for ur reply.
Raghu, you've posted here a number of times. You've probably already
been advised not to use silly abbreviations like "plz" and "ur". They
just make what you write more difficult to read. If you want us to
take the time to read your articles, take the time to spell out the
words.

Given

#define SYSTEM_H

the identifier SYSTEM_H is a macro that expands to nothing. Any uses
of it *outside a preprocessing directive* (such as #if or #ifdef) will
simply vanish. For example, this:
SYSTEM_H int x SYSTEM_H = 42 SYSTEM_H ;
is exactly equivalent to this:
int x = 42 ;

But there's no reason to care what it expands to, because that's not
what it's used for. In the common idiom where a macro is used as a
header guard, the macro name is *only* used for the purpose of
determining whether it's defined or not, using "#ifndef"; what it
expands to is irrelevant.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 3 '07 #8
Keith Thompson wrote:
"raghu" <ra*********@gmail.comwrites:
On Mar 2, 6:28 pm, mark_blue...@pobox.com wrote:
<snip>
To explain a little more for "raghu" - the approach is a standard
convention for ensuring that multiple inclusions of header files
(usually due to being nested in other header files) are "harmless".

If my header called "fred.h" has the form:-

#ifndef FRED_H
#define FRED_H
...
#endif /*FRED_H*/

then the first inclusion will have the macro "FRED_H" undefined, will
define the macro (as an empty macro) and do the other declarations,
definitions etc which the header defines.

Any subsequent inclusions will have "FRED_H" defined, so will do
nothing.
Yes you are correct. I am imlementing exactly like this but one thing
I didn't understand what will be the value assigned FRED_H here. when
the processor looks in to it their must be change in the value. Right.
what will be that value.

Thanks for ur reply.
<snip>
Given

#define SYSTEM_H

the identifier SYSTEM_H is a macro that expands to nothing. Any uses
of it *outside a preprocessing directive* (such as #if or #ifdef) will
simply vanish. For example, this:
SYSTEM_H int x SYSTEM_H = 42 SYSTEM_H ;
is exactly equivalent to this:
int x = 42 ;
A minor question:

Is it simply removed or is it replaced by a space character?

<snip>

Mar 3 '07 #9
Keith Thompson said:

<snip>
Raghu, you've posted here a number of times. You've probably already
been advised not to use silly abbreviations like "plz" and "ur". They
just make what you write more difficult to read. If you want us to
take the time to read your articles, take the time to spell out the
words.
I have already stopped bothering to read his articles, for precisely
this reason. When he starts posting intelligibly, I will consider
reading what he has to say.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 3 '07 #10
Richard Heathfield said:
Keith Thompson said:

<snip>
>Raghu, you've posted here a number of times. You've probably already
been advised not to use silly abbreviations like "plz" and "ur".
They
just make what you write more difficult to read. If you want us to
take the time to read your articles, take the time to spell out the
words.

I have already stopped bothering to read his articles, for precisely
this reason. When he starts posting intelligibly, I will consider
reading what he has to say.
What a fib! A minimal amount of research shows that I do in fact still
read his articles, and even reply to them!

Never mind - I can soon put that right.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 3 '07 #11
santosh wrote:
Keith Thompson wrote:
>Given

#define SYSTEM_H

the identifier SYSTEM_H is a macro that expands to nothing. Any uses
of it *outside a preprocessing directive* (such as #if or #ifdef) will
simply vanish. For example, this:
SYSTEM_H int x SYSTEM_H = 42 SYSTEM_H ;
is exactly equivalent to this:
int x = 42 ;

A minor question:

Is it simply removed or is it replaced by a space character?
The macro is removed. That's what happens when any macro
is expanded: the macro itself is removed, and its expansion is
inserted where the macro used to be.

The replacement for this macro is not a space character,
but a zero-length sequence of preprocessing tokens. A "raw"
character of any kind would be out of place here, since the
program text has by this time been tokenized; translation is
now dealing with (preprocessing) tokens, not with characters.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 3 '07 #12
On Fri, 02 Mar 2007 13:30:54 +0000, Richard Heathfield
<rj*@see.sig.invalidwrote:
Eric Sosman said:
raghu wrote:
#define SYSTEM_H
(Assuming it's just a typo): Before the #define, SYSTEM_H
is not defined and has no value at all. After it, SYSTEM_H is
defined as an object-like macro whose replacement list is empty.

Ah, good point. I realise now that my parallel reply may seem a little
odd, but of course I was thinking of its value when used in
preprocessor directives such as #if.
I hope not, because that would have been wrong. You may have been, and
perhaps were, thinking of the value in a preprocessor expression of an
identifier (well, pp-identifier) which has NOT been #define'd at all.

The usual trick(?) to use a possibly-empty macro in a pp-expression is
#if FOO + 0 /* but not 0 + FOO ! */
/* selected if FOO is 1, unselected if FOO is 0 or empty */
#endif

and #if FOO + 0 >= 3 /* instead of just FOO >= 3 */ etc.

Mar 17 '07 #13
David Thompson said:
I was thinking of [the] value [of an 'empty' #define] when used in
>preprocessor directives such as #if.

I hope not, because that would have been wrong.
I was. If it is convenient, please convince me that I'm wrong. (If not,
don't worry - I'll simply add a note to my to-do list that I should try
to convince myself that I'm wrong, provided of course that I can still
find the end of the list.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 18 '07 #14
Richard Heathfield wrote:
David Thompson said:
I was thinking of [the] value [of an 'empty' #define] when used in
preprocessor directives such as #if.
I hope not, because that would have been wrong.

I was. If it is convenient, please convince me that I'm wrong.
#undef MACRO
#define MACRO /* empty */
#if MACRO
#endif

Since MACRO is defined on the third line, it is expanded as usual. The
result is a line consisting only of #if, which is a syntax error.
There is a special replacement of identifiers with 0, but this is only
after the usual macro replacement, so by the time this is done,
"MACRO" is already gone.

Mar 18 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Morgan Cheng | last post: by
7 posts views Thread by Newbie_sw2003 | last post: by
6 posts views Thread by Niklaus | last post: by
23 posts views Thread by bjk of course | last post: by
21 posts views Thread by Helge Jensen | last post: by
669 posts views Thread by Xah Lee | last post: by
53 posts views Thread by jaso | last post: by
5 posts views Thread by =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.