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 7548301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:39:50+00:00 2026-05-30T09:39:50+00:00

I have a number of small functions which are defined in a .h file.

  • 0

I have a number of small functions which are defined in a .h file. It is a small project (now) and I want to avoid the pain of having declarations and definitions separate, because they change all the time. To avoid multiply-defined symbols, I can either have them static or inline. What should be preferred and why?

I know it is in general bad practice to define functions in headers. You don’t have to mention that in answers, this question is meant technically.

  • 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-30T09:39:52+00:00Added an answer on May 30, 2026 at 9:39 am

    I’d use static inline, but static would work just as well.

    extern and extern inline are out because you’d get multiple external definitions if the header is included in more than one translation unit, so you need to consider static, static inline and inline specification.

    Heptic correctly states in his answer that most compilers consider functions for inlining regardless of whether inline is specified or not, ie the main impact of inline is its effect on linkage.

    However, static definitions have internal linkage, so there’s not much difference between static and static inline; I prefer static inline for function definitions in header files for purely stylistic reasons (rule of thumb: header files should only contain extern declarations, static const variable definitions and static inline function definitions).

    inline without static or extern results in an inline definition, which the standard states (C99 6.7.4, §6)

    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.

    ie inline definitions should always be accompanied by external definitions, which is not what you’re looking for.

    Some more information about the subtleties of C99 inline semantics can be found in this answer, on the Clang homepage and the C99 Rationale (PDF).

    Keep in mind that GCC will only use C99 semantics if -std=c99 or -std=gnu99 is present…

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

Sidebar

Related Questions

I have defined small MXML component which calls web service which returns random number
I have a number of small icons which are draggable via jQuery which i
I have a small file test.txt contains a Long number inside while another piece
I have refactored some views through user defined functions and I want to ensure
I have a file full of C++ code which is a bunch of small
I have a vector containing large number of elements. Now I want to write
I have a number of small REAL Studio apps that use the Speak keyword
On a website I have a number of small PHP scripts to automate changes
In an ASP.NET application, I have a small number of fairly complex, frequently used
I have a security number generator device, small enough to go on a key-ring,

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.