Topic: virtual bases and variable args


Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 28 Jan 1994 00:18:27 GMT
Raw View
>>>>> Stephen Gevers <sg3235@sw1sta.sbc.com> writes:

> I have two questions for the C++ wizards of the world:
> 1.)  Accourding to the ARM, 10.6c

> "Casting from a virtual base class to a derived class is disallowed to
> avoid requiring an implementation to maintain pointers to enclosing
> objects."

> My question is, does RTTI have any effect on this statement.  In
> otherwords, will RTTI cause the appropriate information to be available
> that causes this statement to be false?  If so, will casting from the
> virtual base to a derived class be allowed?

RTTI adds new syntax to the language for accomplishing this; you will be
able to write `derived dp* = dynamic_cast<derived *>(vbase_ptr)'.

Currently, this syntax is explicitly supported in the grammar, though there
has been talk of using the template mechanism (either class or function).

You will still be unable to write `derived dp* = (derived *)vbase_ptr'.

The RTTI mechanism is briefly described in the list of ANSI/ISO resolutions
available from ftp://world.std.com/AW/stroustrup2e/iso.ps.

Jason




Author: sg3235@sw1sta.sbc.com (Stephen Gevers)
Date: 27 Jan 94 20:24:34 GMT
Raw View
I have two questions for the C++ wizards of the world:

1.)  Accourding to the ARM, 10.6c
"Casting from a virtual base class to a derived class is disallowed to avoid
requiring an implementation to maintain pointers to enclosing objects."

My question is, does RTTI have any effect on this statement.  In otherwords,
will RTTI cause the appropriate information to be available that causes this
statement to be false?  If so, will casting from the virtual base to a derived
class be allowed?

2.)  I inherited some code that looks like this:

 int Class::func (...)
 {
  va_list list;
  va_start (list, this);

  ...

  va_end (list);
 }

The code seems to work on my implementation (CFRONT).  However, I don't think
that it should be legal.  It certainly doesn't look portable.  How bad is it?

Stephen Gevers
sg3235@shelob.sbc.com




Author: jason@cygnus.com (Jason Merrill)
Date: Sat, 29 Jan 1994 00:13:42 GMT
Raw View
>>>>> Stan Friesen <swf@tdat.ElSegundoCA.NCR.COM> writes:

> In article <JASON.94Jan27161827@deneb.cygnus.com>, jason@cygnus.com (Jason Merrill) writes:

> |> RTTI adds new syntax to the language for accomplishing this; you will be
> |> able to write `derived dp* = dynamic_cast<derived *>(vbase_ptr)'.
>       ^^^
> Do you *really* mean 'dp*' here rather than '*dp'?

No.  Oops.

> If the cast 'fails' (that is if the real type is wrong) does dynamic cast
> return a NULL pointer, or throw an exception, or what?

It returns NULL in the above example.  If you are working with references
instead, i.e.

derived &dr = dynamic_cast<derived &>(vbase_ob)

and the cast fails, then a Bad_cast exception is thrown.

Jason




Author: swf@tdat.ElSegundoCA.NCR.COM (Stan Friesen)
Date: Fri, 28 Jan 94 15:43:50 PST
Raw View
In article <JASON.94Jan27161827@deneb.cygnus.com>, jason@cygnus.com (Jason Merrill) writes:

I have a couple of questions:
|>
|> RTTI adds new syntax to the language for accomplishing this; you will be
|> able to write `derived dp* = dynamic_cast<derived *>(vbase_ptr)'.
     ^^^
Do you *really* mean 'dp*' here rather than '*dp'?

If the cast 'fails' (that is if the real type is wrong) does
dynamic cast return a NULL pointer, or throw an exception, or what?

--
swf@elsegundoca.ncr.com  sarima@netcom.com

The peace of God be with you.




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 29 Jan 1994 22:11:07 GMT
Raw View
sg3235@sw1sta.sbc.com (Stephen Gevers) writes:

>2.)  I inherited some code that looks like this:
>
> int Class::func (...) {
>  va_list list;
>  va_start (list, this);
>  ...
>  va_end (list);
> }
>
>The code seems to work on my implementation (CFRONT).  However, I don't think
>that it should be legal.  It certainly doesn't look portable.  How bad is it?

No, it's not legal.  I expect that it would work on most implementations,
but not all.  I wouldn't call it portable.

--
Fergus Henderson - fjh@munta.cs.mu.OZ.AU