# How to find out if function are compiler-specific?

This topic is 4932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, in the last month i have been programming i have thought a lot about what of my code will work in other compilers and/or other platforms. Are there some place to check if a function call or other keywords(#pragma for example) depends on your compiler and if they also depend on your platform? As an example in a couple of code samples i have seen this:
#ifdef WIN32
#pragma once
#endif


But ain't #pragma a MSVC specific feature? Will it work on for example Dev-C++(WIN32 version)?

##### Share on other sites
the best way to check is to compile on another platform. everything that the other platform complains about is platform specific. pre-compiler directives, like the #pragma once, are compiler specific and not platform specific. i.e. it could very well work on different platforms depending on what compiler you are using. unless you actually have another platform available upon which to compile, learning which things are different is just going to be an exercise in memorization and, IMHO, not that useful.

In my experience, as long as i've used cross platform libraries (like openGL instead of DirectX) the only thing i have had to change in my gamecode between platforms is the window initialization code and the network code. win32 doesn't work on linux, and the network code is subtily different. otherwise there are endian issues to deal with on certain platforms (powerPC chips are the oppisite endian from intel/amd i believe).

-me

##### Share on other sites
Quote:
 Original post by CHI-kAre there some place to check if a function call or other keywords(#pragma for example) depends on your compiler and if they also depend on your platform?
Documentation. MSDN is a good resource for Windows programming.

Quote:
 But ain't #pragma a MSVC specific feature?
#pragma itself is part of the C language specification, being a preprocessor directive (it stands for "pragmatic information," meaning additional information to assist implementation). The individual pragmas, however, such as #pragma once, #pragma comment, etc, are compiler-specific.

##### Share on other sites
Quote:
 href="http://msdn.microsoft.com/library/">MSDN is a good resource for Windows programming.

I know MSDN and use it very frequently, but the problem is when i compile something in Microsoft Visual Studio 2003 .NET everything works fine, no errors or warnings, but then when someone tries to compile it with Borland C++ Builder(That is the name right?) 835 errors come up and it is very hard to fix because you can't take one error at the time and see if it compiles because there are still 834 left.

Quote:
 the best way to check is to compile on another platform. everything that the other platform complains about is platform specific. pre-compiler directives, like the #pragma once, are compiler specific and not platform specific. i.e. it could very well work on different platforms depending on what compiler you are using. unless you actually have another platform available upon which to compile, learning which things are different is just going to be an exercise in memorization and, IMHO, not that useful.

I know it's a good idea to compile on another platform, currently i only have Windows XP, but will install Fedora or Gentoo next weekend. The problem then is all the different compilers, i can't test my code on ALL compilers so I'll need to somehow check if only some compilers support the keywords.

##### Share on other sites
I think #pragma once might be the equivalent of an #ifndef...#define...#endif inclusion guard.

##### Share on other sites
Quote:
 Original post by ITGERI think #pragma once might be the equivalent of an #ifndef...#define...#endif inclusion guard.

Almost, the compile time of #pragma once are a little faster, at least the was what i read in The Lounge 1 hour ago. Anyway i use #if !defined(x) #define x ... #endif, the #pragma once was just to give an example.

##### Share on other sites
Quote:
Original post by CHI-k
Quote:
 Original post by ITGERI think #pragma once might be the equivalent of an #ifndef...#define...#endif inclusion guard.

Almost, the compile time of #pragma once are a little faster, at least the was what i read in The Lounge 1 hour ago. Anyway i use #if !defined(x) #define x ... #endif, the #pragma once was just to give an example.
#pragma once prevents the compiler from trying to open the same file more than once. Also, IIRC, most compilers ignore all unknown #pragmas, so it's probably safe to put without checking the compiler first.

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×