Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    C++ code in Linux and windows

    Hi all,

    I have a basic question, I have code that is written for linux (has unix specific calls that are not included in windows api) and I need to port it to windows. It must remain backwards compatible with unix environment though.

    What is the best way to achieve this? Currently, I've been going through adding
    #ifndef WIN32
    // perform unix-specific calls
    // perform windows specific calls
    Is this the best way? The project has about 8 or 9 objects being used, so it is fairly small in size, and the basic operations are file I/O with timestamps.

    Thank you all.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Nottingham, England
    You have lots of options, how about encapsulating the different calls into two derived classes providing the service? Sort of like...

    class service
        do_something();  // which calls system_call_x() below to do 'systemsy' stuff
        virtual system_call_x();
    class service_w : public service
        virtual system_call_x();
    class service_l : public service
        virtual system_call_x();
    Store your instance in a pointer to the parent class, but instantiate the one that matches the system you're compiling for. You don't even need to include the class that handles the 'other' platform in each of your builds.
    Linux user #126863 - see

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts