value of preprocessor symbol?

J

Jive

I've got an include-file problem that's driving me nuts. To help try to
solve it, I want to find out what a particular symbol is defined as at a
particular point. I can't figure out how.

I'm using VC++ 6.0. The symbol is _CRTIMP. I've tried

#pragma message(#_CRTIMP)

and every variation of it that I can think of, but no luck.

There must be a way. Yes?

jdadson at yahoo dott com
 
V

Victor Bazarov

Jive said:
I've got an include-file problem that's driving me nuts. To help try to
solve it, I want to find out what a particular symbol is defined as at a
particular point. I can't figure out how.

I'm using VC++ 6.0. The symbol is _CRTIMP. I've tried

#pragma message(#_CRTIMP)

and every variation of it that I can think of, but no luck.

There must be a way. Yes?

Why don't you just use it in a program, like

#define STR(a) #a
#define STRINGIZE(a) STR(a)
#include <iostream>

int main() {
std::cout
<< "The contents of _CRTIMP are ["
<< STRINGIZE(_CRTIMP)
<< "]\n";
return 0;
}
 
J

Jive

Victor Bazarov said:
Jive said:
I've got an include-file problem that's driving me nuts. To help try to
solve it, I want to find out what a particular symbol is defined as at a
particular point. I can't figure out how.

I'm using VC++ 6.0. The symbol is _CRTIMP. I've tried

#pragma message(#_CRTIMP)

and every variation of it that I can think of, but no luck.

There must be a way. Yes?

Why don't you just use it in a program, like

#define STR(a) #a
#define STRINGIZE(a) STR(a)
#include <iostream>

int main() {
std::cout
<< "The contents of _CRTIMP are ["
<< STRINGIZE(_CRTIMP)
<< "]\n";
return 0;
}

Darned good idea. But there's a problem. The program runs embedded in a
piece of machinery that does not have a screen on it. If I compile to run
on the PC instead, I don't have the problem with the include files. Drat,
eh?
 
V

Victor Bazarov

Jive said:
Victor Bazarov said:
Jive said:
I've got an include-file problem that's driving me nuts. To help try
to
solve it, I want to find out what a particular symbol is defined as at
a
particular point. I can't figure out how.

I'm using VC++ 6.0. The symbol is _CRTIMP. I've tried

#pragma message(#_CRTIMP)

and every variation of it that I can think of, but no luck.

There must be a way. Yes?

Why don't you just use it in a program, like

#define STR(a) #a
#define STRINGIZE(a) STR(a)
#include <iostream>

int main() {
std::cout
<< "The contents of _CRTIMP are ["
<< STRINGIZE(_CRTIMP)
<< "]\n";
return 0;
}

Darned good idea. But there's a problem. The program runs embedded in a
piece of machinery that does not have a screen on it. If I compile to run
on the PC instead, I don't have the problem with the include files. Drat,
eh?

You caught my message right before I cancelled it. Unfortunately it is
a true nonsense. If '_CRTIMP' is defined but is empty, it won't work.
I am tired tonight and couldn't come up with a solution that would somehow
provide an empty string for a macro that is defined but doesn't have any
content as compared to one that is defined and expands to a non-empty
string.

V
 
T

Timothy Madden

Jive said:
I've got an include-file problem that's driving me nuts. To help try to
solve it, I want to find out what a particular symbol is defined as at a
particular point. I can't figure out how.

I'm using VC++ 6.0. The symbol is _CRTIMP. I've tried

#pragma message(#_CRTIMP)

and every variation of it that I can think of, but no luck.

There must be a way. Yes?

jdadson at yahoo dott com
Won't this work for you

#error _CRTIMP

"Timothy Madden"
Romania
 
D

Donovan Hawkins

Jive said:
I've got an include-file problem that's driving me nuts. To help try to
solve it, I want to find out what a particular symbol is defined as at a
particular point. I can't figure out how.

It appears you need a way to get the value at compile-time, so you might try
the following (the helper is necessary to get it to completely evaluate x
and y to their values instead of their symbol names):

#define TOKEN_PASTE_HELPER( x, y ) x##y
#define TOKEN_PASTE( x, y ) TOKEN_PASTE_HELPER( x, y )

int main()
{
TOKEN_PASTE( test, _CRTIMP )();
}


If _CRTIMP isn't defined I get "Call to undefined function 'test_CRTIMP'"

If _CRTIMP is empty I get "Call to undefined function 'test'"

If _CRTIME is 5 I get "Call to undefined function 'test5'"

If _CRTIME is xyz I get "Call to undefined function 'testxyz'"

If _CRTIME is something more complicated like "hello" I get a variety of
error messages like "Undefined symbol 'test'" and "Statement missing ;"


Try replacing _CRTIME with your own symbol and put different values in it
to make sure of the error messages your compiler gives. Drop me an email
if you have any questions as I don't read the newsgroup consistantly.

Donovan Hawkins
 
J

jjr2004a

This won't help completely but it gives you some information...

#include <string.h>

#ifdef _CRTIMP
#pragma message("_CRTIMP is defined")
#elif
#pragma message("_CRTIMP is not defined")
#endif

#ifdef _CRTIMP
#pragma message( _CRTIMP )
#endif

#define X
#pragma message( X )

int main(int argc, char** argv)
{
return 0;
}

and got the following output:
_CRTIMP is defined
...\..\src\PragmaExample.cpp(10) : warning C4081: expected 'string';
found '__declspec'
...\..\src\PragmaExample.cpp(14) : warning C4081: expected 'string';
found ')'


The first line is obvious. The second line at least prints out an
error describing what it thinks is wrong. The third line is for
symbols that are defined as empty. Both of these errors are due to
the fact that message expects something enclosed in quotes.

If you look in string.h it defines _CRTIMP as either empty or
__declspec(dllimport). I suspect the definitions in string.h
are repeated elsewhere in other header files and there is nothing
unique about them as defined in string.h.
 
J

jjr2004a

#define TOKEN_PASTE_HELPER( x, y ) x##y
#define TOKEN_PASTE( x, y ) TOKEN_PASTE_HELPER( x, y )

int main()
{
TOKEN_PASTE( test, _CRTIMP )();
}
This is a somewhat better solution than what I suggested.

Then I realized you can just direct the preprocessor's output to a file using
the -P option!!!

This program:
#include <string.h>

#ifdef _CRTIMP
#define X _CRTIMP
#elif
#define X UNDEFINED
#endif

int main(int argc, char** argv)
{
X
return 0;
}

yielded this output:

int main(int argc, char** argv)
{
__declspec(dllimport)
return 0;
}

This feature should solve all of your preprocessing questions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,536
Latest member
VeldaYoung

Latest Threads

Top