git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Inline functions (Re: [PATCH/RFC v7 1/2] Add infrastructure for translating Git with gettext)

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jun 5, 2010, 20:16 UTC
Message-ID
<20100605201652.GA5652@progeny.tock>
In-Reply-To
<AANLkTilRqVaVV5q-7NrserSDr0t4L1D_j8rNIWxtMYe1@mail.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
> As an aside, I'd appreciate a document pointer, what are the
> implications here exactly?
Oh, good point!  I clean forgot to provide that.

"static inline" functions are just like macros, except each argument is evaluated exactly once and the arguments are typechecked.

In the older dialect, what I was suggesting would be written as follows:

 #ifdef NO_GETTEXT
 #define git_setup_gettext() do { } while(0)
 #else
 extern void git_setup_gettext(void);
 #endif

The feature has been part of GCC and various compilers for a long time now. It was finally officially adopted when the C99 standard came out. It "degrades gracefully" in that the Makefile will define inline to nothing on those very old compilers known not to support it, making these into static functions (which is kind of ugly but with most optimizers it tends to produce the same result).

GCC documentation:
  http://gcc.gnu.org/onlinedocs/gcc/Inline.html

C99 documentation (see the "most current draft" of the revised C99 and navigate with PDF bookmarks to Language → Declarations → Function specifiers → Semantics):

  http://www.open-std.org/jtc1/sc22/wg14/www/projects#9899

More important than all that is how the construct gets used and why. For this, see SECTION 2 item 2 ("Ifdefs are ugly") of linux-2.6/Documentation/SubmittingPatches[1]: and take a look at some of the surrounding code (maybe include/linux/kernel.h would be analogous) for examples.

Hope that helps, Jonathan

[1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/SubmittingPatches
Previous: Ævar Arnfjörð BjarmasonNext: Jakub Narebski
Message 16 of 19 in “Add infrastructure for translating Git with gettext”
  1. 0/2 Add infrastructure for translating Git with gettextÆvar Arnfjörð Bjarmason, Jun 5, 2010
  2. 1/2 Add infrastructure for translating Git with gettextÆvar Arnfjörð Bjarmason, Jun 5, 2010
  3. Jonathan NiederJun 5, 2010
  4. Ævar Arnfjörð BjarmasonJun 5, 2010
  5. Jonathan NiederJun 5, 2010
  6. Ævar Arnfjörð BjarmasonJun 5, 2010
  7. Jonathan NiederJun 5, 2010
  8. Ævar Arnfjörð BjarmasonJun 5, 2010
  9. Jonathan NiederJun 12, 2010
  10. Jonathan NiederJun 5, 2010
  11. Ævar Arnfjörð BjarmasonJun 5, 2010
  12. Jonathan NiederJun 5, 2010
  13. Ævar Arnfjörð BjarmasonJun 5, 2010
  14. Jonathan NiederJun 5, 2010
  15. Ævar Arnfjörð BjarmasonJun 5, 2010
  16. Inline functions (Re: [PATCH/RFC v7 1/2] Add infrastructure for translating Git with gettext)Jonathan Nieder, Jun 5, 2010
  17. Jakub NarebskiJun 5, 2010
  18. Ævar Arnfjörð BjarmasonJun 5, 2010
  19. 2/2 Add initial C, Shell and Perl gettext translationsÆvar Arnfjörð Bjarmason, Jun 5, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.