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. Advertising

  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. Advertising

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,170
    Mike Treseler
    Mar 1, 2006
  2. Shin
    Replies:
    5
    Views:
    4,317
  3. The Saqe

    Looking for portable C++ code

    The Saqe, Sep 23, 2003, in forum: C++
    Replies:
    3
    Views:
    356
    Noah Roberts
    Sep 24, 2003
  4. Rolf Hemmerling
    Replies:
    3
    Views:
    764
    Roger Leigh
    Oct 31, 2003
  5. Replies:
    7
    Views:
    921
Loading...

Share This Page