From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: "Inline" functions in C header/source files Date: 23 Jul 2001 12:43:04 GMT Organization: Aachen University of Technology (RWTH) Lines: 37 Message-ID: <9jh64o$qmu$1@nets3.rz.RWTH-Aachen.DE> References: <20010720192958 DOT 28775 DOT 00000394 AT ng-cu1 DOT news DOT cs DOT com> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 995892184 27358 137.226.32.75 (23 Jul 2001 12:43:04 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 23 Jul 2001 12:43:04 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Andrew Clifton wrote: > Both files will compile fine. When I try to link them into an > executable, however, I get a multiple-definition link error. That's to be expected, to some extent. > If I > change some_function to be "extern inline" I get undefined reference > link errors. That almost certainly means that you didn't turn on optimization, or the function marked "inline" was judged not inline-able by the compiler. The official method is to have two copies of the function's source: one marked "extern inline", in a header file, the other unmarked, in one of the source files. It can be done without the second copy, by some preprocessor magic to remove the 'extern', while compiling that "mother" sourcefile. And you have to compile with optimization turned on. This will inline the function from the source found in the header file, where applicable. For those cases that can't be inlined, or where the optimizer believes it to be a bad idea, it'll call the separate, non-inlined version in the source file. > 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. Not each source --- only those that actually use it. For the others, you get a 'defined "static" but not used' warning. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.