Advertisement Jump to content

Archived

This topic is now archived and is closed to further replies.

Qw3r7yU10p!

Portability (#ifdef Considered Harmful)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
#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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
quote:
Original post by petewood
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


guilty

James Simmons
MindEngine Development
http://medev.sourceforge.net

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!