Portable code

Discussion in 'C++' started by BDob, Dec 10, 2003.

  1. BDob

    BDob Guest

    If to write portable code, I want to have "selective compiling." I am not
    sure if this is the right term.

    Basically it should work like this:

    #define WIN32_COMPILE

    class MyClass
    {
    void MySampleMethod(void);
    };

    void MyClass::MySampleMethod(void)
    {
    /*Code scope A*/
    ...

    /Code scope B*/
    ...
    }

    If WIN32_COMPILE defined, I want all statements in Code scope A be compiled and linked into an EXE. Otherwise, Code scope B into the EXE.

    Could someone explain to me how this can be done?

    Also, any other advices and tips for writing portable code are welcome.

    Many thanks!
     
    BDob, Dec 10, 2003
    #1
    1. Advertisements

  2. BDob

    Jack Klein Guest

    On Wed, 10 Dec 2003 04:36:22 GMT, "BDob" <> wrote in
    comp.lang.c++:

    > If to write portable code, I want to have "selective compiling." I am not
    > sure if this is the right term.
    >
    > Basically it should work like this:
    >
    > #define WIN32_COMPILE
    >
    > class MyClass
    > {
    > void MySampleMethod(void);
    > };
    >
    > void MyClass::MySampleMethod(void)
    > {


    #ifdef WIN32_COMPILE

    > /*Code scope A*/


    #else /* not WIN32_COMPILE */

    > /Code scope B*/
    > ...


    #endif /* WIN32_COMPILE */

    > }
    >
    > If WIN32_COMPILE defined, I want all statements in Code scope A be compiled and linked into an EXE. Otherwise, Code scope B into the EXE.
    >
    > Could someone explain to me how this can be done?
    >
    > Also, any other advices and tips for writing portable code are welcome.
    >
    > Many thanks!


    The comments in the #else and #endif directives are optional, but come
    in very handy for maintenance.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
     
    Jack Klein, Dec 10, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eli Bendersky
    Replies:
    1
    Views:
    1,497
    Mike Treseler
    Mar 1, 2006
  2. Shin
    Replies:
    5
    Views:
    4,482
  3. The Saqe

    Looking for portable C++ code

    The Saqe, Sep 23, 2003, in forum: C++
    Replies:
    3
    Views:
    455
    Noah Roberts
    Sep 24, 2003
  4. Rolf Hemmerling
    Replies:
    3
    Views:
    942
    Roger Leigh
    Oct 31, 2003
  5. nickel
    Replies:
    2
    Views:
    445
    Victor Bazarov
    Feb 12, 2004
  6. Robert Bachmann

    Is this code a portable?

    Robert Bachmann, Feb 9, 2004, in forum: C Programming
    Replies:
    7
    Views:
    480
    Francois Grieu
    Feb 11, 2004
  7. Replies:
    7
    Views:
    1,181
  8. grid

    portable code

    grid, Apr 1, 2005, in forum: C Programming
    Replies:
    5
    Views:
    455
    william
    Apr 2, 2005
Loading...