473,405 Members | 2,141 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,405 software developers and data experts.

preprocessor

Hi, im creating a program that will use either OpenGL or Direct3D. Is there any predefined preprocessor

so i can say

Expand|Select|Wrap|Line Numbers
  1. #if OPENGL
  2. /// code ///
  3. #elif DIRECT3D
  4. // code ///
  5. #endif 
if not, is there any possible way of making your own, with out modifying the complier source
Oct 17 '08 #1
7 2227
JosAH
11,448 Expert 8TB
Sure, you can define that macro on the command line of the compiler:
-DOPENGL or -DDIRECTX3D. Read your compiler user manual.

kind regards,

Jos
Oct 17 '08 #2
donbock
2,426 Expert 2GB
Are you asking if you can create your own macro to control conditional compilation? If so, then JosAH (#2) gave you the answer.

Are you asking if there are particular macro names that are commonly used by programmers everywhere to choose between these options?

Are you asking if the OpenGL and DirectX libraries already provide distinctive macros in their header files that you could use to control conditional compilation? (But then how would you choose which header file to include?)

Are you asking if the OpenGL and DirectX libraries require particular distinctive macros to be defined on the command line?
Oct 17 '08 #3
thanks for the replies.

Good point sorry for not being distinctive. Well what i meant was a could your create your own macro to control conditional compilation, to decide what header files to include and what parts of your programme to be used. Was just checking if like for example visual studios in the library somewhere it had any conditional micros.

The wrapper i have made, when initialising, it takes in an argument to see what render api its going to be using.

I dont know how they did it, i guess i could download the sdk source and search through it. but thought it would quicker to ask if someone knew any information to do such a thing or similar.

So anyway how can it be done?

Thanks
Oct 18 '08 #4
donbock
2,426 Expert 2GB
The wrapper i have made, when initialising, it takes in an argument to see what render api its going to be using.
That sounds like run-time configuration. A common way to handle run-time configuration is to abstract a set of device-independent functions, create a data structure of function pointers to each of those functions, then write wrapper functions to make your device-dependent functions match the prototypes of the device-independent functions, then at run-time populate the structure with pointers to the appropriate device-dependent wrapper functions.

On the other hand, you could use conditional compilation. In that case, only one API is ever present at a time. You don't need to specify the API in an argument.
Oct 18 '08 #5
That's a very good point, i guess i could do the wrapper but if i was to use conditional compilation, how would i do that. ive been messing around with it and still end up with the incorrect results. Right now its not my top priority at the moment but it would be useful knowing how to do this properly.

Many thanks for the replies
Oct 19 '08 #6
donbock
2,426 Expert 2GB
Refer to message #2 where JosAH explains how to set macros from the command line. Let's assume that you will use this technique to defined either OPENGL or DIRECT3D. You must also be careful to insure that the command-line specifies the -I include-file path and -L object-library path corresponding to the OPENGL/DIRET3D macro.

(I hope the following snippets are ok with the posting guidelines.)

First, confirm the command-line macros are set properly.
Expand|Select|Wrap|Line Numbers
  1. #if (defined(OPENGL) && defined(DIRECT3D)) || (!defined(OPENGL) && !defined(DIRECT3d))
  2. #error "Command-line macros OPENGL and DIRECT3D defined inconsistently"
  3. #endif
Next, you need to include the proper header files:
Expand|Select|Wrap|Line Numbers
  1. #if defined(OPENGL)
  2. <include the OpenGL headers>
  3. #elif defined(DIRECT3D)
  4. <include the Direct3D headers>
  5. #endif
Approach #1: use wrapper functions.
For each wrapper function, code it something like this ...
Expand|Select|Wrap|Line Numbers
  1. <declaration of the wrapper function>
  2. {
  3. #if defined(OPENGL)
  4.    <call the corresponding OpenGL function>
  5. #elif defined(DIRECT3D)
  6.    <call the corresponding Direct3D function>
  7. #endif
  8. }
Approach #2: no wrapper functions.
Every place where you call a graphics function, code it something like this ...
Expand|Select|Wrap|Line Numbers
  1. #if defined(OPENGL)
  2.    <call the OpenGL function>
  3. #elif defined(DIRECT3D)
  4.    <call the Direct3D function
  5. #endif
Oct 19 '08 #7
thank you very much, you have been very helpful, thanks again
Oct 20 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
24
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was...
16
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the...
13
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...
18
by: /* frank */ | last post by:
My teacher said that array in C is managed by preprocessor. Preprocesser replace all array occurences (i.e. int a ) with something that I don't understand/remember well. What's exactly happens...
13
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int...
9
by: Walter Roberson | last post by:
I have run into a peculiarity with SGI's C compiler (7.3.1.2m). I have been reading carefully over the ANSI X3.159-1989 specification, but I cannot seem to find a justification for the behaviour....
2
by: Paolo | last post by:
I imported a VC++6.0 project into VC++7.1. The conversion operation makes a mess with Preprocessor Definitions, adding a "$(NoInherit)" for each file. For example: I had a DLL project in VC++6.0...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
31
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.