home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!corton!seti!goudurix.inria.fr!daniel.edelson
- From: daniel.edelson@goudurix.inria.fr (Daniel Edelson)
- Newsgroups: comp.lang.c++
- Subject: Re: risky inline
- Keywords: inline, safe programming
- Message-ID: <4117@seti.UUCP>
- Date: 28 Aug 92 08:34:50 GMT
- References: <1992Aug27.142700@uni-paderborn.de>
- Sender: news@seti.UUCP
- Reply-To: Daniel R. Edelson <edelson@sor.inria.fr>
- Organization: INRIA -- Institut National de Recherche en Informatique et Automatique -- Rocquencourt, France
- Lines: 44
-
- In article <1992Aug27.142700@uni-paderborn.de>, trachos@uni-paderborn.de (Konstantin Trachos) writes:
- |>
- |> Consider folowing example:
- |>
- |> // Interface C.hxx -----------------------------
- |> class C{
- |> int a() {return 0;} // OK
- |> inline int b() {return 0;} // OK
- |> int c(); // ...
- |> int d(); // ...
- |> };
- |>
- |> // Code C.cxx ----------------------------------
- |> #include "C.hxx"
- |> inline int C::c() {return 1;}// !
- |> int C::d() {return 0;}// OK
- |>
- |> The Problem is, that #including C.hxxin your main file
- |> will make the cfront handle the C::c() as a function-call
- |> instead of expanding the code.
- |> You can also build more .libs including code invoking C::c().
- |> But the linker will fail, because he is going to miss c__1CFv.
- |>
- |> I think, that a safe compiler requires safe Language-rules,
- |> not only carefull Programmers.
- |>
- |> email: trachos@dat.uni-paderborn.de
-
- According to the draft C++ Standard:
- ``A name of file scope that is explicitly declared
- inline is local to its translation unit.''
- Therefore, C::c() has internal linkage, is local to its translation
- unit, and is not available outside of C.cxx or any other
- implementation file in which it is defined.
-
- When using separate compilation, non-inline functions go
- in implementation files, inline functions go in header files.
-
- In this regard, the language rules are safe.
-
- Daniel.Edelson@inria.fr
-
- (Pardon me if I got the wording slightly wrong, I don't have the
- latest draft with me so I referred to the 14 May 1991 draft.)
-