Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I've been reading a few articles about writing compatible code (cross platform, cross compiler) and I'm astonished about some of the things I read here[^].

I know compilers don't always implement all features, but pre-defined macros are how we can tell what we can and cannot do (in a way). For my surprise, compilers don't always correctly define these macros.

"Please notice that not all compliant compilers provides the correct pre-defined macros. For example, Microsoft Visual C++ does not define __STDC__, or Sun Workshop 4.2 supports C94 without setting __STDC_VERSION__ to the proper value. Extra checks for such compilers must be added."

"For example, IBM xlC supports Unix without setting any of the __unix__ macros."

I was trying to write a few macros that would abstract anyone who uses it from these differences. Just for the sake of it. I mean, I know how to correct most of these issues, but it's the heck of a job for a one man show... It's just endless!

It's not like I need every single issue resolved, but hey, portable code is portable, right?

So the question is: is there any project out there that already does this? SourceForge lists some alternatives, but they all seem to be tools (BuildTool, CMake, SCons, etc) and that's not quite what I'm looking for.

I think this is where open source really kicks in. Lots of people all adding definitions from their OSs, compilers, hardware, etc. If there is none, do you think it would be interesting to create a project like that?

An example. I defined this:
C++
#if defined(unix) || defined(__unix__) || defined(__unix)
#	define _USING_UNIX 1
#else
#	define _USING_UNIX 0
#endif

#ifdef _WIN32
#	define _USING_WINDOWS 1
#else
#	define _USING_WINDOWS 0
#endif

Which seems correct, but then I read that observation about IBM xlC.
Posted
Updated 22-Jun-12 19:56pm
v2
Comments
Richard MacCutchan 23-Jun-12 5:22am    
Life is hard!
Did you have a question by the way?
AndreFratelli 23-Jun-12 8:53am    
The question is there...
Richard MacCutchan 23-Jun-12 9:29am    
OK, I found it "is there any project out there that already does this?".
Well, quite possibly, but you would need to look at every open source project on the internet to be sure.
Richard MacCutchan 23-Jun-12 9:32am    
On a more serious note, I would suggest you look at the GNU projects as many of them are built to run on multiple systems; primarily UNIX but often include Windows.
Aescleal 23-Jun-12 13:18pm    
I've just tested __STDC__ on every version of Visual C++ since 1997 and they all supported the macro. Are you sure you're not compiling your files as C++ or as C without /Za?

AFAIK C++98 doesn't specify __STDC__ so that might be your problem.

The best C++ development platform across OS-s is Qt[^]. It is also much more powerful than .NET 4.0
 
Share this answer
 
I think you are looking for something like Boost.Config[^]

If there is none, do you think it would be interesting to create a project like that?

Boost[^] covers this, and many, many other things, and it's regularly tested.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sandeep Mewara 26-Jun-12 14:06pm    
Interesting. 5!
Espen Harlinn 26-Jun-12 14:54pm    
Thank you, Sandeep :-D
I haven't heard of something as light as you're suggesting.
Have you had a look at
http://sourceforge.net/projects/pobase/[^]?

It goes toward that way but I am not whether it is terribly popular.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900