#ifdef //If the compiler is running under Windows
#define llint __int64
#elif //If the compiler is running under Linux
#define llint long long
#endif
But for the #ifdef and #elif I don't know what to put there that would detect which OS the compiler is running under. I'd appreciate any insight you can give, though. I could very well be using these preprocessor directives wrong, or there may be a better way. I'm all ears =)
🔒 Locked
Preprocessor Directives and Detecting Linux/Windows
Advertisement
Original Post
I'm currently working on a project that I'm trying to make portable between both Linux and Windows. I've recently stumbled upon a problem that cannot be solved using the standard methods provided in C++, so I'm going to have to rely on platform-specific functions to finish my project. More to the point, my problem is that I cannot use the standard fstream's read() function to fully access files of larger than 2 Gigabytes. My current angle on this is to use #ifdef and other prepocessor calls to swap out words for platform-specific functions (namely Linux's and Window's 64-bit read() functions). What I'd like to do, though, is to detect what OS the compiler is running under, and then replace the words as necessary. For example, Windows' version of a 64-bit integer is an __int64 and Linux's version is a long long. I'd like to use the following statement:
I don't know what directives you should use either.
I can offer you another solution though. Have you thought about splitting up your >2GB file in several smaller files, so you can still use the portable functions?
I've got to ask though... what kind of huge file are you trying to open?
I can offer you another solution though. Have you thought about splitting up your >2GB file in several smaller files, so you can still use the portable functions?
I've got to ask though... what kind of huge file are you trying to open?
Just use your own ones. You can normally specify extra defines with whatever compiler you are using. Just make something up and use that.
Other than that, I think _WIN32 is pretty standard, but I'm not sure.
Other than that, I think _WIN32 is pretty standard, but I'm not sure.
Quote:
Original post by Kalasjniekof
I don't know what directives you should use either.
I can offer you another solution though. Have you thought about splitting up your >2GB file in several smaller files, so you can still use the portable functions?
I've got to ask though... what kind of huge file are you trying to open?
Since you're interested, I hope you don't mind me redirecting you ;)
Basically, I'm starting with a 10g file, and my goal is to split it up such that it is portable... it's the splitting up of the file that's the problem, though.
See the thread here
Quote:
Original post by rick_appleton
Just use your own ones. You can normally specify extra defines with whatever compiler you are using. Just make something up and use that.
Other than that, I think _WIN32 is pretty standard, but I'm not sure.
I'm not sure what you mean by use my own defines... the whole preprocessor thing is new to me as of this morning (not including the #includes that I've been using blindly for the past couple of months). I've searched online for various tutorials using the preprocessor directives, but I haven't been able to find a compilable piece of code that illustrates how to use them incredibly well, yet, so I don't have any good examples of how to use the functions.
Well, most of the time you can determine someone's platform by what compiler they're using, and just about every compiler defines certain macros:
gcc --> __GNUC__
vs --> _MSC_VER
and so on... although there are tricky things that might happen if you're for instance trying to compile your win32 app with cygwin or mingw's gcc, but then again, the 'long long' I believe would then work under that, and if you're using gcc you might not need to be using windows API calls directly anyway.
Personally, I still think you're better off using the systems mentioned above, with defining your own preproc defines and assigning your own meaning to them.
gcc --> __GNUC__
vs --> _MSC_VER
and so on... although there are tricky things that might happen if you're for instance trying to compile your win32 app with cygwin or mingw's gcc, but then again, the 'long long' I believe would then work under that, and if you're using gcc you might not need to be using windows API calls directly anyway.
Personally, I still think you're better off using the systems mentioned above, with defining your own preproc defines and assigning your own meaning to them.
Quote:
Original post by SiCrane
Pre-defined C/C++ Compiler Macros
Ooo, this looks promising! THanks SiCrane =)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement