Compile directives

B

bcr07548

I am writing a C++ wrapper class for a library that was available in C
but am having some trouble because, at some point, one function was
replaced by a similar one. I would like to have it so my wrapper class
will work with either version of the library (I use both depending on
the system I am using) but there doesn't seem to be any #defines in the
library that will help me do this using an #ifdef test. Since #ifdef
directives only check for identifiers defined at the compiler level
with #define directives and not identifiers defined in the actual C/C++
code itself, I was wondering if there is any compiler level directive
to see if an identifier has been declared at the code level? What I
would like to be able to do is something like this:

#if_in_scope pthread_yield_np
pthread_yield_np();
#else
pthread_yield();
#endif

Does anyone have any ideas on how I could accomplish something like
this in a more or less standard way? If it helps, I am compiling with
GCC 4. If there isn't a standard way, does anyone know of a compiler
specific pragma that might get the job done?

-Brandon R
 
V

Victor Bazarov

I am writing a C++ wrapper class for a library that was available in C
but am having some trouble because, at some point, one function was
replaced by a similar one. I would like to have it so my wrapper
class will work with either version of the library (I use both
depending on the system I am using) but there doesn't seem to be any
#defines in the library that will help me do this using an #ifdef
test. Since #ifdef directives only check for identifiers defined at
the compiler level with #define directives and not identifiers
defined in the actual C/C++ code itself, I was wondering if there is
any compiler level directive to see if an identifier has been
declared at the code level?

Of course not. At the preprocessor level (or stage) there are no
identifiers except macros and preprocessor directives (keywords).
There are no scopes, no types, no functions, no objects...
What I would like to be able to do is
something like this:

#if_in_scope pthread_yield_np
pthread_yield_np();
#else
pthread_yield();
#endif

Does anyone have any ideas on how I could accomplish something like
this in a more or less standard way? If it helps, I am compiling with
GCC 4. If there isn't a standard way, does anyone know of a compiler
specific pragma that might get the job done?

If you have discovered that there was a change from a system to another
system, or from a compiler version to another version, you can alwasy try
to branch using implementation-defined macros for the version, or for the
system... Example: MSVC++ has _WIN32 usually defined, UNIX is usually
defined on different variations of Unix.

V
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top