[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | C++ |
Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) |
Moderator: | DECCXX::AMARTIN |
|
Created: | Fri Nov 06 1987 |
Last Modified: | Thu Jun 05 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3604 |
Total number of notes: | 18242 |
3432.0. "Type Cast Done Inconsistently" by AMCUCS::CMURPHY () Tue Feb 04 1997 17:59
This is a Problem Reported by Rational Software.
Rational is porting products to Digital UNIX using Digital's C++ compiler.
They have a reliance on Bristol's WIND/U product.
Severity: Show-Stopper
Digital UNIX V4.0
cxx -V
DEC C++ V5.4-006 on Digital UNIX (Alpha)
I have reproduced this using V5.5-004 on Digital UNIX V4.0. Below is the
information I received from Rational. NOTE: This problem goes away when
using -cfront, but this is not an option due to the WIND/U requirement.
---
There seems to be a bug with type casting.
In the program below, I have two classes declared: Inner and Outer.
Class Outer contains a class Inner member.
Class Outer also defines a cast operator that casts a class Outer
reference to a class Inner reference.
The problem is that the cast operator is NOT ALWAYS INVOKED on DEC!!
--------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
class Inner {
public:
char buff[20];
};
class Outer {
public:
int n;
Inner contents;
operator Inner& ();
};
Outer::operator Inner& ()
{
printf( "\t*** DBG: got to & cast\n" );
return contents;
}
void func( Inner& anInner ) {
printf( "func: arg=0x%p val=\"%s\"\n", &anInner, anInner.buff );
}
main()
{
Outer anOuter;
anOuter.n = 0;
strcpy( anOuter.contents.buff, "test" );
printf( "main:: anOuter=0x%p val=\"%s\"\n", &anOuter, anOuter.contents.
buff );
Inner& inner1 = anOuter;
printf( "inner1=0x%p\n", &inner1 );
Inner& inner2 = (Inner&)anOuter;
printf( "inner2=0x%p\n", &inner2 );
func( ((Inner&)anOuter) );
return 0;
}
--------------------------------------------------------------
############ OUTPUT: DEC UNIX ############
zowie:/usr/users/murphey % cxx -o x2 x2.cxx
zowie:/usr/users/murphey % x2
main:: anOuter=0x11fffeb70 val="test"
*** DBG: got to & cast
inner1=0x11fffeb74
inner2=0x11fffeb70
func: arg=0x11fffeb70 val=""
>>>> In the above output, you see that the cast operator is
>>>> ONLY invoked by the IMPLICIT cast in the line:
>>>> Inner& inner1 = anOuter;
############ OUTPUT: SOLARIS ############
hercules:/people/murphey % CC -o x2 x2.cc
hercules:/people/murphey % x2
main:: anOuter=0xeffff5d4 val="test"
*** DBG: got to & cast
inner1=0xeffff5d8
*** DBG: got to & cast
inner2=0xeffff5d8
*** DBG: got to & cast
func: arg=0xeffff5d8 val="test"
>>>> In this output, you see that the cast operator is invoked
>>>> by EACH cast, explicit or implicit.
############ HP-UX ############
dougal:/people/murphey % CC -o x2 x2.cc
dougal:/people/murphey % x2
main:: anOuter=0x7b03a8d8 val="test"
*** DBG: got to & cast
inner1=0x7b03a8dc
*** DBG: got to & cast
inner2=0x7b03a8dc
*** DBG: got to & cast
func: arg=0x7b03a8dc val="test"
dougal:/people/murphey %
>>>> This output is identical to the SOLARIS output.
---------------------------------------------------------------------------
We have a LOT of code that does this style of type.
Any help you can give us will be greatly appreciated.
T.R | Title | User | Personal Name | Date | Lines |
---|
3432.1 | | SPECXN::DERAMO | Dan D'Eramo | Tue Feb 04 1997 19:05 | 3 |
| This looks like topic 2794 here to me.
Dan
|
3432.2 | | AMCUCS::CMURPHY | | Wed Feb 05 1997 15:50 | 10 |
| Okay. So where does the compiler stand today, 2 years later?
Is this addressed by any of the ANSI enhancements to come in V5.6?
Is it even a consideration?
Should I append future replies/questions to note 2794?
-Chris Murphy
Software Partner Engineering
DTN 543-3643
|