Portability (#ifdef Considered Harmful)
Hi there
Hopefully this has caught your eye because you were reading the same thread as I was the other day. I haven''t been able to find it again to post this follow up so have started a new one.
I wanted to post a link to one of Herb Sutter''s articles from CUJ but it wasn''t online (I have the paper version). Anyway I pulled it out and there was this reference at the bottom of the article:
#ifdef Considered Harmful
ABSTRACT
We believe that a C programmer’s impulse to use #ifdef in an attempt at portability is usually a mistake. Portability is generally the result of advance planning rather than trench warfare involving #ifdef. In the course of developing C News on different systems, we evolved various tactics for dealing with differences among systems without producing a welter of #ifdefs at points of difference. We discuss the alternatives to, and occasional proper use of, #ifdef.
Anyway, hope this provides insights and is useful to all you good folks out there.
Pete
Despite its age its a good point. Reading #ifdef code is pure hell at times because you have to keep both platforms in mind. Splitting the project up and using an interface to bridge the two (with implementation linked in) has always struck me as easier to read and maintain in the long run.
quote:Original post by m_e_my_self
I would like to point out that it''s from 1992 though...
The point they are making is hardly any less relevant now.
--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
It''s a good point, and one that C++ programmers really should know by now: Isolation of parameterizations is a good thing. It''s why we avoid ten-page switch statements, and it''s why separate system stuff should really go in separate places.
"Sneftel is correct, if rather vulgar." --Flarelocke
"Sneftel is correct, if rather vulgar." --Flarelocke
#ifdef is a godsend. For example, loading a dll on linux is quite different from loading a dll in windows (function names and what you input into those functions) so therefore, advanced planning what do jack shit for you, you need a way to define which dll loading code you need.
James Simmons
MindEngine Development
http://medev.sourceforge.net
James Simmons
MindEngine Development
http://medev.sourceforge.net
quote:Original post by Sneftel
It''s a good point, and one that C++ programmers really should know by now: Isolation of parameterizations is a good thing. It''s why we avoid ten-page switch statements, and it''s why separate system stuff should really go in separate places.
"Sneftel is correct, if rather vulgar." --Flarelocke
could you go into greater detail? I''m not sure what you''re talking about but I am interested :/
James Simmons
MindEngine Development
http://medev.sourceforge.net
quote:Original post by neurokaotix
#ifdef is a godsend. For example, loading a dll on linux is quite different from loading a dll in windows (function names and what you input into those functions) so therefore, advanced planning what do jack shit for you, you need a way to define which dll loading code you need.
I assume you haven''t read the article then
quote:Original post by petewoodquote:Original post by neurokaotix
#ifdef is a godsend. For example, loading a dll on linux is quite different from loading a dll in windows (function names and what you input into those functions) so therefore, advanced planning what do jack shit for you, you need a way to define which dll loading code you need.
I assume you haven''t read the article then
guilty
James Simmons
MindEngine Development
http://medev.sourceforge.net
quote:Original post by neurokaotix
#ifdef is a godsend. For example, loading a dll on linux is quite different from loading a dll in windows (function names and what you input into those functions) so therefore, advanced planning what do jack shit for you, you need a way to define which dll loading code you need.
Write two separate cpp files, one that wraps the linux version, one the windows version, presenting a consistent interface and compile/link with the right one as directed by your make- or project file. Having multiple versions of the code in a single file is a bad idea (messy code, unnecessary recompilations, etc).
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[edited by - Fruny on December 10, 2003 6:05:14 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement