Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Compiler Directives Not Working

Reply
Thread Tools

Compiler Directives Not Working

 
 
shane.tietjen@gmail.com
Guest
Posts: n/a
 
      02-08-2006
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?

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      02-08-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      02-08-2006
(E-Mail Removed) 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
>

 
Reply With Quote
 
Jay_Nabonne
Guest
Posts: n/a
 
      02-08-2006
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

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      02-08-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
shane.tietjen@gmail.com
Guest
Posts: n/a
 
      02-08-2006
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.

 
Reply With Quote
 
shane.tietjen@gmail.com
Guest
Posts: n/a
 
      02-08-2006
Could you explain what you mean by "reserved" and by "You can't use it
in your code."?
Thanks

 
Reply With Quote
 
shane.tietjen@gmail.com
Guest
Posts: n/a
 
      02-08-2006
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.

 
Reply With Quote
 
Ben Pope
Guest
Posts: n/a
 
      02-08-2006
(E-Mail Removed) 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...
 
Reply With Quote
 
shane.tietjen@gmail.com
Guest
Posts: n/a
 
      02-08-2006
<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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why %e not in time.strftime directives? Leo jay Python 3 12-14-2008 06:52 AM
help with compiler directives Kenneth Lantrip C Programming 19 07-21-2004 03:24 AM
Compiler directives for Perl? Yash Perl Misc 3 02-07-2004 02:59 PM
compiler directives Philip Townsend ASP .Net 1 02-05-2004 09:03 PM
Page Directives DotNetWorks ASP .Net 1 01-05-2004 06:55 PM



Advertisments