468,241 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Compiler Directives Not Working

Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.

[\test.cpp]

Also, if you do:
#ifndef _UNUSED_NAME_3223458
#define TEST123 0
#endif

Insert this prior to the other one(so you test for not defined before
defined), TEST123 will have a value of 0 and not 6789.

No errors or warnings.

It is almost as if the variable you testing( _UNUSED_NAME_3223458 which
is never defined at any time) is in an unknown state at the time you
test it.

What is going on here?

Feb 8 '06 #1
17 1569
sh***********@gmail.com wrote:
Working in VS 2003.
Perhaps you should ask in 'microsoft.public.vc.language'...
in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.
By _definition_ if 'TEST123' has the value 6789 (or whatever), it means
that either 'TEST123' is defined _elsewhere_ *as well* as here, or that
"_UNUSED_NAME_3223458" macro is in fact _defined_ and that's how the C++
preprocessor knows to define 'TEST123".

What you're trying to doubt here is the very basic functionality of the
preprocessor. I am _sure_ it's you who's made the mistake. Are you sure
it's "ifdef" and not "ifndef"?...

[\test.cpp]

Also, if you do:
#ifndef _UNUSED_NAME_3223458
#define TEST123 0
#endif

Insert this prior to the other one(so you test for not defined before
defined), TEST123 will have a value of 0 and not 6789.

No errors or warnings.

It is almost as if the variable you testing( _UNUSED_NAME_3223458 which
is never defined at any time) is in an unknown state at the time you
test it.

What is going on here?


Impossible to say. Your code fragments do not carry enough information.
You're asking for a rather big leap from those fragments to the notion
that everything else is OK, and you didn't screw up somehow. I'd rather
believe the compiler.

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #2
sh***********@gmail.com wrote:
Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
_UNUSED_NAME_3223458 is reserved to the implementation. You can't use
it in your code.
#define TEST123 6789
#endif

Feb 8 '06 #3
On Wed, 08 Feb 2006 09:00:48 -0800, shane.tietjen wrote:
Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.


Put

#undef _UNUSED_NAME_3223458

right before the #ifdef in test.h. If that fixes it, then
_UNUSED_NAME_3223458 is defined *somewhere*. (Preprocessor defines in the
project settings perhaps?)

Also, what if you change it to

#ifdef _UNUSED_NAME_3223458foo

? Does it still behave the same?

- Jay

Feb 8 '06 #4

<sh***********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Working in VS 2003.

in a header file:

[test.h]

#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

[\test.h]

in the implementation file:

[test.cpp]

\\the value of TEST123 will be 6789 or whatever value is assigned to it
even though _UNUSED_NAME_3223458 was never defined and is not present
in any other files.

[\test.cpp]

Also, if you do:
#ifndef _UNUSED_NAME_3223458
#define TEST123 0
#endif

Insert this prior to the other one(so you test for not defined before
defined), TEST123 will have a value of 0 and not 6789.

No errors or warnings.

It is almost as if the variable you testing( _UNUSED_NAME_3223458 which
is never defined at any time) is in an unknown state at the time you
test it.

What is going on here?


You don't show how you're checking the value of TEST123. How do you know
its value if it hasn't been defined? Testing for a specific value may not
be a valid test if it is never defined in the first place. (I'm not sure if
that's mandated by the standard, or an implementation detail, though.)

-Howard

Feb 8 '06 #5
I thought I was very clear. TEST123 and _UNUSED_NAME_3223458 are not
defined anywhere in my code nor are they present in any file on the
system. This means that there is no possible way they could be
defined. Not defined.

I understand the compiler is smarter than I am. Thats why I use it
instead of writing Assembly.

Feb 8 '06 #6
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?
Thanks

Feb 8 '06 #7
I have tried the #undef solution before and it produced the same
results. But it IS NOT defined anywhere on the local machine in any
file. I know this becaue I just made up the name with a bunch of
random numbers and then searched for it.

And yes, it will behave the same no matter what name you choose.

Feb 8 '06 #8
sh***********@gmail.com wrote:
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?


The standard says that identifiers that start with an underscore
followed by a capital alpha character are reserved for the implementation.

As are identifiers prefixed with double underscore.

This means you have undefined behaviour, regardless of how likely that
identifier is likely to appear in the implementation.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 8 '06 #9
<Quote>
You don't show how you're checking the value of TEST123. How do you
know
its value if it hasn't been defined? Testing for a specific value may
not
be a valid test if it is never defined in the first place. (I'm not
sure if
that's mandated by the standard, or an implementation detail, though.)

-Howard
<\Quote>

I check it using the debugger at runtime. I searched every file on the
local machine and "TEST123" and "_UNUSED_NAME_xxxx" not listed as being
part of any other file other than the lines I showed you in the .h file
and .cpp file we are dealing with.

Feb 8 '06 #10
<quote>
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?


The standard says that identifiers that start with an underscore
followed by a capital alpha character are reserved for the
implementation.

As are identifiers prefixed with double underscore.
This means you have undefined behaviour, regardless of how likely that
identifier is likely to appear in the implementation.
<quote>

Okay I accept that. I wasn't trying to confuse anyone with the name.
Truth is, the name doesn't matter so assume my original problem without
the "_" at the beginning. Sorry for any confusion.

Feb 8 '06 #11
Ben Pope wrote:
sh***********@gmail.com wrote:
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?

The standard says that identifiers that start with an underscore
followed by a capital alpha character are reserved for the implementation.

As are identifiers prefixed with double underscore.


Actually, as are identifiers _containing_ double underscores (17.4.3.1.2).
This means you have undefined behaviour, regardless of how likely that
identifier is likely to appear in the implementation.


V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #12

<sh***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
<Quote>
You don't show how you're checking the value of TEST123. How do you
know
its value if it hasn't been defined? Testing for a specific value may
not
be a valid test if it is never defined in the first place. (I'm not
sure if
that's mandated by the standard, or an implementation detail, though.)

-Howard
<\Quote>

I check it using the debugger at runtime. I searched every file on the
local machine and "TEST123" and "_UNUSED_NAME_xxxx" not listed as being
part of any other file other than the lines I showed you in the .h file
and .cpp file we are dealing with.


I'd question the debugger, then. Try actually using code or more
preprocessor directives to test if it's defined, and what its value is. I
bet it's simply not defined, which is confusing the debugger. Try something
like this to test:

// in header file:
#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

// in a function somewhere in a file which includes that header:
#ifdef TEST123
int testInt = TEST123;
#else
int testInt = 0;
#endif
// Now, check or display the value of testInt!

-Howard


Feb 8 '06 #13
sh***********@gmail.com wrote:
I thought I was very clear. TEST123 and _UNUSED_NAME_3223458 are not
defined anywhere in my code nor are they present in any file on the
system. This means that there is no possible way they could be
defined. Not defined.

I understand the compiler is smarter than I am. Thats why I use it
instead of writing Assembly.


No, the compiler is not smarter. It's just more careful at following
the rules imposed on it.

Read the FAQ 5.8, and follow its recommendations. Then we can talk. So
far you're just too frustrated about your problem to hear what others are
telling you.

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #14
sh***********@gmail.com wrote:
<quote>
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?

The standard says that identifiers that start with an underscore
followed by a capital alpha character are reserved for the
implementation.

As are identifiers prefixed with double underscore.
This means you have undefined behaviour, regardless of how likely that
identifier is likely to appear in the implementation.
<quote>

Okay I accept that. I wasn't trying to confuse anyone with the name.
Truth is, the name doesn't matter so assume my original problem without
the "_" at the beginning. Sorry for any confusion.


No. We won't assume anything. Assumption is the mother of all f***-ups.

Post complete minimal code that demonstrates your problem.

V
--
Please remove capital As from my address when replying by mail
Feb 8 '06 #15
<quote>
I thought I was very clear. TEST123 and _UNUSED_NAME_3223458 are not
defined anywhere in my code nor are they present in any file on the
system. This means that there is no possible way they could be
defined. Not defined. I understand the compiler is smarter than I am. Thats why I use it
instead of writing Assembly.


No, the compiler is not smarter. It's just more careful at following
the rules imposed on it.

Read the FAQ 5.8, and follow its recommendations. Then we can talk.
So
far you're just too frustrated about your problem to hear what others
are
telling you.
V
<\quote>

No I am not frustrated. I actually solved the problem a while ago by
modifying other code so I was not required to use the initial #ifdef in
the header file. No frustrations here at all. I just don't know why
the code was behaving the way it was. And it IS "Smarter" than me. LOL.

Feb 8 '06 #16
The way I meant assume: Similar to writing a mathematical proof,
"Assume the problem is the same as it was originally and get rid of the
"_" in the name". Since the name of the variable doesn't matter( as
long as it is a valid name ), it doesn't change the original nature of
the problem which is what I wanted you to "asume".

sorry for any confustion.

Feb 8 '06 #17
"Howard" <al*****@hotmail.com> wrote in message
news:TD*********************@bgtnsc05-news.ops.worldnet.att.net...

<sh***********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
<Quote>
You don't show how you're checking the value of TEST123. How do you
know
its value if it hasn't been defined? Testing for a specific value may
not
be a valid test if it is never defined in the first place. (I'm not
sure if
that's mandated by the standard, or an implementation detail, though.)

-Howard
<\Quote>

I check it using the debugger at runtime. I searched every file on the
local machine and "TEST123" and "_UNUSED_NAME_xxxx" not listed as being
part of any other file other than the lines I showed you in the .h file
and .cpp file we are dealing with.


I'd question the debugger, then. Try actually using code or more
preprocessor directives to test if it's defined, and what its value is. I
bet it's simply not defined, which is confusing the debugger. Try
something like this to test:

// in header file:
#ifdef _UNUSED_NAME_3223458 //this is not defined anywhere at anytime
#define TEST123 6789
#endif

// in a function somewhere in a file which includes that header:
#ifdef TEST123
int testInt = TEST123;
#else
int testInt = 0;
#endif
// Now, check or display the value of testInt!

-Howard


Heck, I think I would just do:

#ifdef UNUSED_NAME_3223458
#slakjfsl;adkjfsal;kdjf
#endif

and see if the compiler barfs or not.
Feb 9 '06 #18

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ágoston Bejó | last post: by
28 posts views Thread by Skybuck Flying | last post: by
18 posts views Thread by smnoff | last post: by
29 posts views Thread by Ark | last post: by
41 posts views Thread by p_cricket_guy | last post: by
18 posts views Thread by andreas.luethi | last post: by
reply views Thread by norseman | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.