Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6013447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:32:58+00:00 2026-05-23T02:32:58+00:00

When I try to build this code inline void f() {} int main() {

  • 0

When I try to build this code

inline void f() {}

int main()
{
    f();
}

using the command line

gcc -std=c99 -o a a.c

I get a linker error (undefined reference to f). The error vanishes if I use static inline or extern inline instead of just inline, or if I compile with -O (so the function is actually inlined).

This behaviour seems to be defined in paragraph 6.7.4 (6) of the C99 standard:

If all of the file scope declarations for a function in a translation unit include the inline function specifier without extern, then the definition in that translation unit is an inline definition. An inline definition does not provide an external definition for the function, and does not forbid an external definition in another translation unit. An inline definition provides an alternative to an external definition, which a translator may use to implement any call to the function in the same translation unit. It is unspecified whether a call to the function uses the inline definition or the external definition.

If I understand all this correctly, a compilation unit with a function defined inline as in the above example only compiles consistently if there is also an external function with the same name, and I never know if my own function or the external function is called.

Isn’t this behaviour completely daft? Is it ever useful to define a function inline without static or extern in C99? Am I missing something?

Summary of answers

Of course I was missing something, and the behaviour isn’t daft. 🙂

As Nemo explains, the idea is to put the definition of the function

inline void f() {}

in the header file and only a declaration

extern inline void f();

in the corresponding .c file. Only the extern declaration triggers the generation of externally visible binary code. And there is indeed no use of inline in a .c file — it’s only useful in headers.

As the rationale of the C99 committee quoted in Jonathan’s answer explicates, inline is all about compiler optimisations that require the definition of a function to be visible at the site of a call. This can only be achieved by putting the definition in the header, and of course a definition in a header must not emit code every time it is seen by the compiler. But since the compiler is not forced to actually inline a function, an external definition must exist somewhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:32:59+00:00Added an answer on May 23, 2026 at 2:32 am

    Actually this excellent answer also answers your question, I think:

    What does extern inline do?

    The idea is that “inline” can be used in a header file, and then “extern inline” in a .c file. “extern inline” is just how you instruct the compiler which object file should contain the (externally visible) generated code.

    [update, to elaborate]

    I do not think there is any use for “inline” (without “static” or “extern”) in a .c file. But in a header file it makes sense, and it requires a corresponding “extern inline” declaration in some .c file to actually generate the stand-alone code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this code: void group::build(int size, std::string *ips){ /*Build the LL after receiving the
I've try to compile this code: #include <iostream> #include <cstdlib> using namespace std; #define
I am getting this error when I try to build for the device: Code
For some reason, when I try to run this code, all I get is
When I try to execute this code: package uk.org.infectogenomics.agent; import uk.org.infectogenomics.Agent.qa.Quasr; public static void
When I try to build my project I get the following message in the
Sometimes when i try to build/compile a downloaded source, i get following warning: ld:
I've included: #import QuartzCore/QuartzCore.h but when I try to build, I get the error
Whenever I try to build my iPhone app in Xcode 3.2.1 I get an
This does not always happen, but sometimes when I try to build a (large)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.