home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1166 < prev    next >
Encoding:
Text File  |  1992-09-12  |  1.7 KB  |  45 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: How About a Pragma Specifying All Functions Virtual?
  5. Message-ID: <1992Sep12.180508.6483@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <#7vnafk.feustel@netcom.com>
  8. Date: Sat, 12 Sep 1992 18:05:08 GMT
  9. Lines: 34
  10.  
  11. feustel@netcom.com (David Feustel) writes:
  12.  
  13. >Coplien's book "Advanced C++" makes the point that very little overhead
  14. >would be incurred in most programe even if all functions were declared
  15. >virtual and that some programs might even run faster than equivalent C
  16. >programs using switch constructs to achieve the same effects. Why not
  17. >define a pragma that would make all class functions virtual by
  18. >default?
  19.  
  20. Nothing prevents a C++ implementation from providing such a pragma.
  21.  
  22. But IMHO pragmas which change language semantics are very dangerous.
  23.  
  24. 1.  If you miss including the pragma in one place, or remove it
  25.     from all but one place, you can get bizarre program failures,
  26.     not necessarily caught in testing.
  27.  
  28. 2.  If the code moves to another compiler which doesn't support the
  29.     pragma, it will be silently ignored and the program will have a
  30.     different meaning.  If you are very lucky, the compiler will
  31.     warn about the pragma, or the program will fail in testing.
  32.     (In Standard C, unknown pragmas are not errors.)
  33.  
  34. 3.  The code might move to a compiler which has the same pragma, but
  35.     with a different meaning.  Example:
  36.     #pragma once
  37.     Everybody knows this pragma, right?  It turns on special features
  38.     for the customer engineer.  You turn them off again with
  39.     #pragma offce
  40.     (I didn't think this one up, but it's my favorite.)
  41. -- 
  42.  
  43. Steve Clamage, TauMetric Corp, steve@taumet.com
  44. Vice Chair, ANSI C++ Committee, X3J16
  45.