Topic: How About a Pragma Specifying All Functions Virtual?


Author: feustel@netcom.com (David Feustel)
Date: Sat, 12 Sep 92 00:09:34 GMT
Raw View
Coplien's book "Advanced C++" makes the point that very little overhead
would be incurred in most programe even if all functions were declared
virtual and that some programs might even run faster than equivalent C
programs using switch constructs to achieve the same effects. Why not
define a pragma that would make all class functions virtual by
default?
--
Dave Feustel N9MYI <feustel@netcom.com>

RE Drug Warriors who enjoy making a "good" bust: I'm sure the Salem
Witch Hunters enjoyed their law enforcement achievements too.




Author: steve@taumet.com (Steve Clamage)
Date: Sat, 12 Sep 1992 18:05:08 GMT
Raw View
feustel@netcom.com (David Feustel) writes:

>Coplien's book "Advanced C++" makes the point that very little overhead
>would be incurred in most programe even if all functions were declared
>virtual and that some programs might even run faster than equivalent C
>programs using switch constructs to achieve the same effects. Why not
>define a pragma that would make all class functions virtual by
>default?

Nothing prevents a C++ implementation from providing such a pragma.

But IMHO pragmas which change language semantics are very dangerous.

1.  If you miss including the pragma in one place, or remove it
    from all but one place, you can get bizarre program failures,
    not necessarily caught in testing.

2.  If the code moves to another compiler which doesn't support the
    pragma, it will be silently ignored and the program will have a
    different meaning.  If you are very lucky, the compiler will
    warn about the pragma, or the program will fail in testing.
    (In Standard C, unknown pragmas are not errors.)

3.  The code might move to a compiler which has the same pragma, but
    with a different meaning.  Example:
 #pragma once
    Everybody knows this pragma, right?  It turns on special features
    for the customer engineer.  You turn them off again with
 #pragma offce
    (I didn't think this one up, but it's my favorite.)
--

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16