473,503 Members | 11,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compile directives

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

Aug 1 '06 #1
1 1579
bc******@creighton.edu wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
10351
by: James | last post by:
Can someone please help me with these errors? #include <iostream> #include <string> class holder { private: int vid; string vtype;
10
4419
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
13
3552
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the...
1
3101
by: Michael Fitzpatrick | last post by:
Is it possible to set a variable with the value of a compile time constant. Example: #Const MODE_STR = "Mode1" dim strMode as String = MODE_STR Obviously this doesn't work. Is there a way...
5
5500
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: ...
6
2648
by: Tom | last post by:
I am developing my pages on my development machine and then copying to the production server. I am not pre-compiling, I am using the 'dynamic compile' feature. This is working fine except that...
13
2744
by: rincewind | last post by:
I remember reading an article (was it Herb Sutter's?) that recommended avoiding using directives. While I quite understand this recommendation for headers, what's wrong in using directive in .cpp...
76
4016
by: jacob navia | last post by:
Since standard C doesn't provide any way for the programmer to direct the compiler as to how to layout structures, most compilers provide some way to do this, albeit in different forms. ...
14
2563
by: lagman | last post by:
All, I'm looking for a tool that is able to take my code base (which is full of preprocessor directives) and spit out source code that is "clean" of any preprocessor directives based on the...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
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...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.