Subject: inline and external linkage

From: [email-masked]
Date: Wed, 10 Feb 1999 07:41:19 -0600 (CST)

Full_Name: Pete Forman
Version: 2.1.10
CVS_Date: 
OS: IRIX 6.4
X_Server: NCD
Submission from: (NULL) (195.60.31.15)

Problem: fvwm/misc.h gives an error for the use of "online".

Explanation: The MIPSpro 7.2 compiler on IRIX 6.4 supports inline
    with internal linkage only, not external.  The configure script
    tests for internal only.

Note: Current ANSI/ISO C does not support inline.
    The imminent standard C9X does support inline, with some obvious
    restrictions on what may go in an external inline function.
    ANSI/ISO C++ does not support external linkage.

Fix alternative 1:  Alter the test case in the configure script.
    
    int main() {
    } extern $ac_kw foo() {
    ; return 0; }

Fix alternative 2: Add an extra option to the config stuff so that 
    there are separate "inline" and "extern_inline" instances.

Fix alternative 3: Rewrite code that uses extern inline" to be internally
    linked.

--
Visit the official FVWM web page at <URL:http://fvwm.math.uh.edu/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 12 Feb 1999 00:14:22 +0100

On Wed, Feb 10, 1999 at 07:41:19AM -0600, [email-masked] wrote:
> Problem: fvwm/misc.h gives an error for the use of "inline".

Am I being dumb? Inline is supposed to be a C++ feature,
isn't it? I see that RelieveWindow and RelieveWindowHH in
borders.c are declared inline functions. There are some
other places where it's used too. Apart from this is can't
fathom why a function longer than 80 lines should be an
inline. Seems like tons of useless duplicate code to me.

Shouldn't we remove 'inline' altogether?

Bye

Dominik

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Fri, 12 Feb 1999 00:19:52 +0100

Looking at the gcc info page I see that gcc supports inline
for plain C but it's not ansi C:

  `-ansi'
       Support all ANSI standard C programs.

       This turns off certain features of GNU C that are incompatible
       with ANSI C, such as the `asm', `inline' and `typeof' keywords ...

Bye

Dominik

---

From: Pete Forman <[email-masked]>
Date: Fri, 12 Feb 1999 09:57:10 GMT

> inline. Seems like tons of useless duplicate code to me.

I did put some notes in my bug report, but I've just double checked
C9X and had it wrong.  C9X and C++ both have the same behaviour.
External linkage of inline is permitted but not in the way that
RelieveWindow[HH] tries to do it.  An inline function must be defined
in every translation unit that calls it.  The extern qualifier serves
to make sure that all translation units with a definition of an inline
function have identical definitions for it.

My fix alternatives 1 and 2 are inadequate.

Inline function definitions belong in header files.  If they are not
able to be inlined, e.g. with C89, then they belong in a C file.  So
if we are to be able to compile in both environments you'd need the
following sort of ugliness.

/* relieve.h */

#ifdef HAVE_INLINE
/* define the functions */
#include "relieveP.c"
#else
/* just declare the functions */
extern void RelieveWindow(FvwmWindow *, Window,
                          int, int, int, int, GC, GC, int);
extern void RelieveWindowHH(FvwmWindow *,Window,
                            int,int,int,int, GC,GC, int, int);
#endif

/* relieve.c or borders.c */

#ifndef HAVE_INLINE
#include "relieveP.c"
#endif

/* relieveP.c */

extern inline void RelieveWindow(FvwmWindow *t,Window win,
                                 int x,int y,int w,int h,
                                 GC ReliefGC,GC ShadowGC, int hilite)
{
...

I have only addressed language standards: C89, C9X, C++.  Compilers
may have limitations or extensions.  For instance the AIX C compiler
can inline functions even though there is no inline declaration.
Remember that inline is just a hint, there are similarities with the
register qualifier.

 > Shouldn't we remove 'inline' altogether?

Probably.  It is only really useful for short functions.  Given the
size of RelieveWindow[HH] the overhead of a normal function call is
minimal.  I wouldn't be too surprised if some compilers decided that
these functions were too big and "outlined" them anyway.
-- 
Pete Forman
Western Geophysical
[email-masked]
--
Visit the official FVWM web page at <URL:http://fvwm.math.uh.edu/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 15 Feb 1999 19:30:59 +0100

>     ANSI/ISO C++ does not support external linkage.

I have removed the 'inline' declaration from the offending functions
(fvwm2 as well as several modules). The 'inlined' functions were
quite large anyway. The funny thing is that the executable has become
48 bytes larger (Linux PC).

Bye

Dominik