home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12961 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.9 KB  |  58 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!math.fu-berlin.de!pbinfo!trachos
  3. From: trachos@uni-paderborn.de (Konstantin Trachos)
  4. Subject: risky inline
  5. Message-ID: <1992Aug27.142700@uni-paderborn.de>
  6. Keywords: inline, safe programming
  7. Sender: news@uni-paderborn.de (News Uni-Paderborn)
  8. Nntp-Posting-Host: sunkist
  9. Organization: Uni-GH Paderborn, Germany
  10. Date: Thu, 27 Aug 1992 12:27:00 GMT
  11. Lines: 45
  12.  
  13. Maybe this topic is well known, but I realy want to know the reason, 
  14. inline has been introduced for.
  15.  
  16. Inline-expansion is surely more effective than #defines, but it isn't
  17. less risky than that.
  18.  
  19. Consider folowing example:
  20. C.hxx and C.cxx are used to build C.lib.
  21. After that you use only C.hxx and C.lib:
  22.  
  23. // Interface C.hxx -----------------------------
  24.    class C{
  25.           int a() {return 0;}    // OK
  26.    inline int b() {return 0;}    // OK
  27.           int c();        // ...
  28.       int d();        // ...
  29.    };
  30. // EOF C.hxx -----------------------------------
  31.  
  32. // Code C.cxx ----------------------------------
  33.    #include "C.hxx"
  34.    inline int C::c() {return 1;}// !
  35.           int C::d() {return 0;}// OK
  36. // EOF C.hxx -----------------------------------
  37.  
  38.  
  39. The Problem is, that #including C.hxxin your main file
  40. will make the cfront handle the C::c() as a function-call
  41. instead of expanding the code.
  42. You can also build more .libs including code invoking C::c().
  43. But the linker will fail, because he is going to miss c__1CFv.
  44.  
  45. I think, that a safe compiler requires safe Language-rules,
  46. not only carefull Programmers.
  47.  
  48.  
  49. -- 
  50. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=
  51.  _          __  
  52. | |  _    _/ /   Uni-GH Paderborn, FB 14   
  53. | |/ /   /  __/  Dipl.-Inf. K. Trachos   
  54. | |\ \   / /     Pohlweg 47-49                      Tel: +49 5251 60 3227
  55. |_| \_\ /__/     D-4790 Paderborn                   FAX: +49 5251 60 3238
  56.                                       email: trachos@dat.uni-paderborn.de
  57. -=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  58.