Thursday, February 01, 2007

GCC compiler directives

When ever you start coding on separate platforms, you need to start
thinking about compiler directives.   That way, you can write
separate code for different needs. Follow the break to find out how to take advantage of GCC compiler directives.



To get the list of directives
from gcc use the command

echo "" | gcc -E -dM -

Using this you can find the gcc for linux and MacOS have the directive
'__linux' and '__APPLE__'

An example of how I use this info is my OpenGL header file requests.

#if __linux
#define  GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>
#include <GL/glut.h>
#else
#if __APPLE__
#include <opengl/gl.h>
#include <opengl/glu.h>
#include <glut/glut.h>
#endif
#endif

...Read more

No comments: