Writing portable code for use with VC++ and BC++

Back Up Next

VC resource compiler not understand Borland style definitions of BITMAP, ICON in *.rc, all this must be in separated files.
This will not compile:
MY_ICON ICON {
00,00,00,11,11,11,
............................
}

Use instead
MY_ICON ICON "myicon.ico"
VC don't have xmsg it have class exception() and all classes derived from it. In OWL I use macro XBASE, for  BC it xmsg for VC - exception(), another problem exception doesn't have function: string why() -> const char* what(), In OWL I use macros XWHY_STR, for BC it will be why().c_str, for VC what(), If you have better solution let me know :).
All exceptions in VC derived from class exemption, therefore class exemption have to be last class,(before (...)), In Borland there are classes that not derived from xmsg : Bad_cast() and Bad_typeid().
Bad_cast() and Bad_typeid() this is old names, VC and BCB uses new ANSI names bad_cast() and bad_typeid(), for OWL my solution was define this classes as synonyms, and define macros THROW_BAD_CAST , THROW_TYPE_ID for BC this is : Bad_cast() and Bad_typeid(), for VC this is : bad_cast("OWL_badcast"), and bad_typeid("OWL_type_id")
Derive all your exception classes from TXOwl, or TXBase.
VC check return type of functions and if you declare in base class virtual function, derived class have to define this function with exactly the same parameters and return type, not as for Borland, check template TDocTemplate, it create function that returns pointer to newly created doc or View, with new doc/view Type, it will not compile with VC, them have to return pointer to base class.
Problem with type casting, for example
  class Base{
      public:
          Base* GetBase(){return Next;};
     protected:
      Base* Next;
  };
  class Derived: public Base{
    public:
        Derived* GetDerived(){return (Derived*)Next;}; // this will not work
  };
  for(Derived* i = list.GetDerived(); i; i = i->GetDerived() ) // this code perfectly work in BC, not work with VC

instead use:
  class Derived: public Base{
    public:
        ...
  };
  for(Derived* i = (Derived*)list.GetBase(); i; i = (Derived*)i->GetBase() ) // this code perfectly work in BC and VC
Names scope:
  for(int i = 0; i<10;i++){
    // some work
  }
  for(int i = 0; i<25;i++){
    // some work
  }
 
Perfect with BC, will not compiled with VC, use other name for variable i, or define i out of loop.
  int i;
  for(i = 0; i<10;i++){
    // some work
  }
  for( i = 0; i<25;i++){
    // some work
  }
 
or:
  for(int i = 0; i<10;i++){
    // some work
  }
  for( int j = 0;j<25;j++){
    // some work
  }
Revised: December 04, 1999.


Copyright © 1998-2001 Yura Bidus. All rights reserved.