First, thanks for all the replies, the ifdef thing works now, let me explain what happened. Consider the following code:
#ifdef WIN32 #include <windows.h> #else // any other include for linux #endif
#ifdef WIN32
int APIENTRY WinMain( ....)
{#else
int main( int argc, char *argv[])
{#endif
return 0; }
Trying to compile this file in VC++ 6 gives some error about #else not expected. The weird thing is that moving the first portion (the one with the include directives) to a header file works like a charm.
Can anyone explain this ???
At least the problem is no longer a problem :)
Eli
PS. A google search showed that the header file features.h might contain some definitions that can be used to determine the platform, at least on Linux. The way the ifdefs are set up at the moment take into consideration only Win32 and EVERYTHING else. I'd like to somehow detect Linux and glibc (yes i know about __GLIBC__).
Well, thanks for the help
On Thu, Jul 03, 2003, Voguemaster wrote about "Cross platform code":The problem is very basic: Linux and Win32 have different include files for some things and placing #include directives inside #ifdef doesn't do the trick (it nullifies the #ifdef possibly ?????).
You probably made some mistake - #include doesn't nullify #ifdef or anything of that sort :) (you might want to refer to any C book, or the "cpp" info-page, for more information)
You can have something like
#ifdef LINUX_SYSTEM #include <this/is/available/only/on/linux.h> #else #include <a/windows/include/file.h> #endif
And when you compile on the Linux system, add a "-DLINUX_SYSTEM" in the command line. Alternatively, you can use predefined macros that are automatically defined on one system and not on the other. For example, last time I checked, the C preprocessor defines "linux" on linux systems. So you can replace the above example with
#ifdef linux #include <this/is/available/only/on/linux.h> #else #include <a/windows/include/file.h> #endif
The macro __linux__ is also defined in Linux, I believe. A similar macro
(whose name I don't remember) is defined by default on Microsoft's C compiler
on Windows.
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
