C++ code : Visual C++ and Borland C++ compilers 
Author Message
 C++ code : Visual C++ and Borland C++ compilers

Hi everybody!

My question is about moving C++ code from the Borland 5.xx compiler to the
Microsoft VC 6.0
In our huge project is frequently used the callback mechanism and almost all
classes are derived from the VObject base class that have the perform()
method like below:

typedef     boolean (VObject::*method)();
typedef     boolean (VObject::*method1)(long);
boolean VObject::perform(method m, long param)
{
 volatile boolean retval;
 method1 *p = (method1 *)(&m);
 method1  q = *p;
 retval = (this->*q)(param);
 return retval;

Quote:
}

The problem is that a passed method m not always gets 1 parameter according
to its definition. In some cases it get more parameters, in some cases does
not get parameters at all (design mistakes).
The application built with a Borland compiler does not feels this mismatch,
however in Microsoft the application crashes in going out the called
function (q) from the instruction stack.
If anybody know a simple way to force the Microsoft compiler to generate a
code like the Borland one without multiple corrections in the sources?

Many thanks for advice.



Fri, 11 Jan 2002 03:00:00 GMT  
 C++ code : Visual C++ and Borland C++ compilers
Maybe there is a way to tamper with the compiler's internals and make
this code somehow function on VC++ without a runtime crash. Still, the
best solution is to fix the code for two reasons: every hack is at best
a temporary solution and future compiler versions and service packs
might force you to repeat this process again. Worse yet, according to
the Standard, using a pointer to member to call a member function with
an incompatible signature is undefined. Founding a non trivial
application on these very shaky foundations is very problematic.

Danny Kalev

"The ANSI/ISO C++ Professional Programmer's Handbook"
http://www.amazon.com/exec/obidos/ASIN/0789720221
http://www.devx.com/free/books/bookreview.asp?bookid=286

Quote:

> Hi everybody!

> My question is about moving C++ code from the Borland 5.xx compiler to the
> Microsoft VC 6.0
> In our huge project is frequently used the callback mechanism and almost all
> classes are derived from the VObject base class that have the perform()
> method like below:

> typedef     boolean (VObject::*method)();
> typedef     boolean (VObject::*method1)(long);
> boolean VObject::perform(method m, long param)
> {
>  volatile boolean retval;
>  method1 *p = (method1 *)(&m);
>  method1  q = *p;
>  retval = (this->*q)(param);
>  return retval;
> }

> The problem is that a passed method m not always gets 1 parameter according
> to its definition. In some cases it get more parameters, in some cases does
> not get parameters at all (design mistakes).
> The application built with a Borland compiler does not feels this mismatch,
> however in Microsoft the application crashes in going out the called
> function (q) from the instruction stack.
> If anybody know a simple way to force the Microsoft compiler to generate a
> code like the Borland one without multiple corrections in the sources?

> Many thanks for advice.



Sat, 12 Jan 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. C++ code : Visual C++ and Borland C++ compilers

2. Will Borland C++ compile with Microsoft Visual C++ Compiler

3. Visual C++ Compiler and ISO/ANSI C++ Code

4. How to compile Visual C++ 1.0 source code using Visual C++ 4.0

5. Conversion Borland c++ to Visual c++!

6. Linking Visual C++ libs to Borland C++ programs

7. Borland C/C++ vs MS Visual C/C++ ?

8. Borland c++ Builder, Visual c, gnu c++, which one is better

9. Microsoft Visual C++ or Borland C++ ?

10. Borland C++ 4.5 vs Visual C++

11. Visual C++ V4.0 vs Borland C++ V5.0

12. Borland C++ vs Turbo C++ Visual Edition

 

 
Powered by phpBB® Forum Software