473,651 Members | 2,765 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_n p
pthread_yield_n p();
#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 1592
bc******@creigh ton.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_n p
pthread_yield_n p();
#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
10357
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
4449
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 Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
13
3581
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 amount of preprocessor directives used in these code. Can anyone please tell me how to actually use these preprocessor directives in a more professional way like selecting particular lines of code suited for some particular hardware etc...
1
3115
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 to achieve the same thing???
5
5508
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: #if TEST
6
2652
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 everytime I change a page on the production server I need to restart IIS to effect the change. If I don't restart IIS, it tries to recompile but gets and error ( 'cannot execute a program......vbc.exe......). Am I missing something which allows...
13
2781
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 files?
76
4099
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. Microsoft (and lcc-win) uses #pragma pack(1) Gcc uses __attribute__ {(packed)}
14
2590
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 options I choose (possibly via some kind of user input screen). Does such a tool exist? A Visual Studio plugin would be even better. FYI: I have requirements to rid my code of all conditionally compiled
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
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 we have to send another system
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.