By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,419 Members | 1,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,419 IT Pros & Developers. It's quick & easy.

Portable code

P: n/a
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!

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Wed, 10 Dec 2003 04:36:22 GMT, "BDob" <bd*****@at.att.net> 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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.