Thread View: comp.std.c++
2 messages
2 total messages
Started by David Feustel
Sat, 12 Sep 1992 00:09
How About a Pragma Specifying All Functions Virtual?
Author: David Feustel
Date: Sat, 12 Sep 1992 00:09
Date: Sat, 12 Sep 1992 00:09
11 lines
876 bytes
876 bytes
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.
Re: How About a Pragma Specifying All Functions Virtual?
Author: Steve Clamage
Date: Sat, 12 Sep 1992 18:05
Date: Sat, 12 Sep 1992 18:05
34 lines
1828 bytes
1828 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads