Portable code

B

BDob

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!
 
J

Jack Klein

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top