home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13005 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.1 KB

  1. Path: sparky!uunet!mcsun!corton!seti!goudurix.inria.fr!daniel.edelson
  2. From: daniel.edelson@goudurix.inria.fr (Daniel Edelson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: risky inline
  5. Keywords: inline, safe programming
  6. Message-ID: <4117@seti.UUCP>
  7. Date: 28 Aug 92 08:34:50 GMT
  8. References: <1992Aug27.142700@uni-paderborn.de>
  9. Sender: news@seti.UUCP
  10. Reply-To: Daniel R. Edelson <edelson@sor.inria.fr>
  11. Organization: INRIA -- Institut National de Recherche en Informatique et Automatique -- Rocquencourt, France
  12. Lines: 44
  13.  
  14. In article <1992Aug27.142700@uni-paderborn.de>, trachos@uni-paderborn.de (Konstantin Trachos) writes:
  15. |> 
  16. |> Consider folowing example:
  17. |> 
  18. |> // Interface C.hxx -----------------------------
  19. |>    class C{
  20. |>           int a() {return 0;}    // OK
  21. |>    inline int b() {return 0;}    // OK
  22. |>           int c();        // ...
  23. |>       int d();        // ...
  24. |>    };
  25. |> 
  26. |> // Code C.cxx ----------------------------------
  27. |>    #include "C.hxx"
  28. |>    inline int C::c() {return 1;}// !
  29. |>           int C::d() {return 0;}// OK
  30. |> 
  31. |> The Problem is, that #including C.hxxin your main file
  32. |> will make the cfront handle the C::c() as a function-call
  33. |> instead of expanding the code.
  34. |> You can also build more .libs including code invoking C::c().
  35. |> But the linker will fail, because he is going to miss c__1CFv.
  36. |> 
  37. |> I think, that a safe compiler requires safe Language-rules,
  38. |> not only carefull Programmers.
  39. |> 
  40. |>                                       email: trachos@dat.uni-paderborn.de
  41.  
  42. According to the draft C++ Standard:
  43.     ``A name of file scope that is explicitly declared
  44.       inline is local to its translation unit.''
  45. Therefore, C::c() has internal linkage, is local to its translation
  46. unit, and is not available outside of C.cxx or any other
  47. implementation file in which it is defined.
  48.  
  49. When using separate compilation, non-inline functions go
  50. in implementation files, inline functions go in header files.
  51.  
  52. In this regard, the language rules are safe.
  53.  
  54. Daniel.Edelson@inria.fr
  55.  
  56. (Pardon me if I got the wording slightly wrong, I don't have the 
  57. latest draft with me so I referred to the 14 May 1991 draft.)
  58.