[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-cxx-dev
Subject:    RE: CXX-DEV: How does it work?
From:       "Ramnik Dahiya" <ramnik_dahiya () persistent ! co ! in>
Date:       2004-08-19 7:58:11
Message-ID: GDECKFGFCMFELHLOEOKICEPKCBAA.ramnik_dahiya () persistent ! co ! in
[Download RAW message or body]

Hi,

I tried it with purify and it worked.
However, Purify reported some Uninitialised Memory Read/Copy
messages.The output was the same.
I'm not well versed with purify, so can't make out much of it.

The purify version is
 2003a.06.13 Proto 0143 040312 HP-UX
and I'm using
 aCC: HP ANSI C++ B3910B A.03.39

Hope you can provide some insight.

Thanks,
Ramnik



-----Original Message-----
From: owner-cxx-dev@cxx.cup.hp.com
[mailto:owner-cxx-dev@cxx.cup.hp.com]On Behalf Of Dennis Handly
Sent: Thursday, August 19, 2004 12:19 PM
To: cxx-dev@cxx.cup.hp.com
Subject: Re: CXX-DEV: How does it work?


>From: Sreenivas Prasad <prasad_sreenivas@yahoo.com>
>I expected the following program to crash or do something abnormal.  But
>this works OK on HP-UX.

This is an illusion.  If you ran purify it would catch it.

        printf("\n ctor derived");
                ^^
Why are you using a silly Fortran (or COBOL?) style of formatting?
In C & C++, the newline goes at the end.  That way it gets flushed properly.

    void OnlyInDerived() { val = 10; }
 Base baseInst;
 Derived *deriInst = (Derived*)&baseInst;
 deriInst->OnlyInDerived();

>Any ideas?
Sreenivas

Basically, the cast does nothing.  The sizeof Base is 1.  The sizeof
Derived is 4.  When you store into val, it overwrites the 3 padding bytes.
And you are lucky that baseInst is aligned on a word boundary.
 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE cxx-dev
 _________________________________________________________________
 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE cxx-dev
 _________________________________________________________________
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic