Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualNightCreature83

Posted 12 December 2012 - 06:47 AM

Just to add to the above posts...while you can certainly author platform-specific code using the pre-processor, in practice that's really messy. It's not hard to imagine how convoluted a real window-creation function would look if you just put the code for multiple platforms all in the same places with #if's and #ifdef's thrown in everywhere. So it's generally better (IMO) to avoid that whenever possible by using other means to selectively compile code. For instance at my current company, we tag platform-specific cpp files with a suffix that tells our build system what platform it should be compiled for. That way each file can contain a whole bunch of implementation-specific code for a single class or a group of related functions.

Another way of doing this is by telling the make/solution/project/build script mechanisme which platform it's target is and then include platform specific code files. No need to specially tag cpps or h files, if they are in the target make/solution/project/build script as long as they are in there it will be compiled in for that platform. However you would still want to use the preprocessor in certain cases where implementation is only slightly different depending on which platform you compile for, and we are getting to the int changing values stuff for particular platforms here. You don't have to rely on the pre processor commands build in to the compiler with this matter either as you can specify per make/solution/project/build script what defines it should set.

You will also want to invest in some interface design as well so that the code that is platform specific presents the same interface to the rest of the code so that the system is easy to interact with.

#1NightCreature83

Posted 12 December 2012 - 06:42 AM

Just to add to the above posts...while you can certainly author platform-specific code using the pre-processor, in practice that's really messy. It's not hard to imagine how convoluted a real window-creation function would look if you just put the code for multiple platforms all in the same places with #if's and #ifdef's thrown in everywhere. So it's generally better (IMO) to avoid that whenever possible by using other means to selectively compile code. For instance at my current company, we tag platform-specific cpp files with a suffix that tells our build system what platform it should be compiled for. That way each file can contain a whole bunch of implementation-specific code for a single class or a group of related functions.

Another way of doing this is by telling the make/solution/project/build script mechanisme which platform it's target is and then include platform specific code files. No need to specially tag cpps or h files, if they are in the target make/solution/project/build script as long as they are in there it will be compiled in for that platform. However you would still want to use the preprocessor in certain cases where implementation is only slightly different depending on which platform you compile for, and we are getting to the int changing values stuff for particular platforms here. You don't have to rely on the pre processor commands build in to the compiler with this matter either as you can specify per make/solution/project/build script what defines it should set.

PARTNERS