delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/20/19:47:18

Lines: 52
X-Admin: news AT cs DOT com
From: andyclifton AT cs DOT comNOSPAM (Andrew Clifton)
Newsgroups: comp.os.msdos.djgpp
Date: 20 Jul 2001 23:29:58 GMT
Organization: CompuServe (http://www.compuserve.com/)
Subject: "Inline" functions in C header/source files
Message-ID: <20010720192958.28775.00000394@ng-cu1.news.cs.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Question:
(And, yes, I know that this has been covered before. I couldn't find an answer
in the archives...)

Is it or is it not possible to "inline" functions in C source files under GCC,
and, if it is possible, how do I do it?

The docs for GCC have "inline" described under C extensions, and I believe I
have seen C programs that used it. However, I can't seem to get it to work.
Here's what I've got:

/*
 *Header.h
 */
inline void some_function(int, char)
{
    /* Does whatever */
}

--------------------------

/*
 *Source1.c
 */
#include "Header.h"

/* Calls some_function() somewhere */

-----------------------------

/*
 *Source2.c
 */
#include "Header.h"

/* Also calls some_function()... */


Both files will compile fine. When I try to link them into an executable,
however, I get a multiple-definition link error. If I change some_function to
be "extern inline" I get undefined reference link errors. Using "static inline"
works, but I have a feeling that it might actually be including a copy of the
function in the object file for each source. Plus, "static inline" generates
"defined but not used" complier errors for every inline function that is
defined but not used.

What's the proper way to do this?
Andrew Clifton
andyclifton AT cs DOT comNOSPAM
http://ourworld.cs.com/_ht_a/andyclifton/
"The trouble about trying to make yourself stupider than you really are is that
you very often succeed." ~C. S. Lewis

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019