473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1729
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ágoston Bejó | last post by:
Hi there, In the old Pascal-times, you could set compiler switches in the source code, with a syntax like {$G+}, things like that (I don't remember them accurately anymore). Is there something...
28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
126
by: ramyach | last post by:
Hi friends, I need to write a parallel code in 'C' on the server that is running SGI Irix 6.5. This server supports MIPS Pro C compiler. I don't have any idea of parallel C languages. I looked...
5
by: cody | last post by:
the following leads to an error (note that TEST is not defined): #if TEST string s = @" #"; // <-- the error is "preprocessing directive expected" #endif also, here we get the same error: ...
18
by: smnoff | last post by:
Ok, I am think I am a little more knowledgeable about C and pointers, ughh. And likewise, I want to fix C.....and not so much to make a C++ or Java or C# or even D like language. So, if I...
29
by: Ark | last post by:
A function int foo(struct T *x) { return (x+1)-x; } should always return a 1, no matter how T is defined. (And int could be replaced with ptrdiff_t for you pedants.) For one thing, it was...
41
by: p_cricket_guy | last post by:
Please see this test program: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <limits.h> 4 5 int main (void) 6 { 7 int y = -2147483648; 8 int x = INT_MIN;
18
by: andreas.luethi | last post by:
Hi All Compile a our source with BM XL C/C++ Enterprise Edition V8.0 for AIX (Version: 08.00.0000.0000) produces a lot of Informational message like this: "aaalib.c", line 671.1: 1506-412 (I)...
0
by: norseman | last post by:
Hendrik van Rooyen wrote: ============================================= .....dreaded.... Yep! I know the feeling. Got lots of those T-Shirts. ;) I re-read your original post. I got the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.