Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #397308

Re: gcc and 'include'

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: gcc and 'include'
Date 2026-03-30 07:59 -0700
Organization A noiseless patient Spider
Message-ID <86ecl11hze.fsf@linuxsc.com> (permalink)
References (3 earlier) <20260327164757.00001882@yahoo.com> <10q92ue$pt4g$1@dont-email.me> <20260329103756.000027f0@yahoo.com> <10qbp51$1pi82$1@dont-email.me> <20260329213901.0000335b@yahoo.com>

Show all headers | View raw


Michael S <already5chosen@yahoo.com> writes:

> On Sun, 29 Mar 2026 13:56:49 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>
>> On 2026-03-29 03:37, Michael S wrote:
>>
>>> On Sat, 28 Mar 2026 10:25:33 -0700
>>> Andrey Tarasevich <noone@noone.net> wrote:
>>
>> ...
>>
>>>> The outcome is perfectly predictable, as long as you folow the ODR
>>>> rules of C language.
>>>
>>> Sometimes it works.  Sometimes it does not.  The Standard permits both
>>> behaviors.
>>> If it is not called 'unpredictable' then I don't know what is.
>>
>> Using external inline gives the implementation a choice.  in general,
>> the implementation will choose whichever is better in a given
>> situation, which is usually a good thing.
>> Sometimes it will call the inline definition, sometimes it will call
>> the external one.  In most cases, you handle that by making sure the
>> inline definition is the same as the external one - there's some not
>> very difficult techniques using the preprocessor so that you only
>> have to write the code once, and the same definition is used for both.
>> If, for any reason, it's important to you that the behavior be
>> different when calling the external version than the inline one,
>> that's also easy to arrange.
>> What's the problem?
>
> If you don't see situation presented by Bart as a problem then we don't
> have enough of common ground to continue the conversation.
>
> My own conclusion is simple - my decades-long custom of never using
> inline without static is even wiser than I imagined.

It's important to realize that local and global inline functions
serve different purposes.  In most cases what I think people want
and expect is a function that is always expanded inline, except
perhaps in cases where the compiler has reasons to think that is
not a good idea.  These cases should always use 'static';  as far
as I can tell there is never any reason not to.

The more unusual case is where we want the possibility that a
function might be expanded inline, but it is also important that
there be a single definition in some translation unit.  For
reasons of ease of compilation, C requires that which translation
unit that is be identified explicitly;  that is done by giving
a non-inline definition in a particular source file.  Because
this situation doesn't come up very much, it isn't used very much
(except sometimes by accident), so it isn't surprising that most
people don't know what is meant by a non-static inline function.

The rule is simple:  Always use 'static' for inline functions,
unless there is a good reason not to.  And in those cases it's
important to understand just how non-static inline functions
work, and to observe the relevant criteria so that they work
properly.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

gcc and 'include' Bart <bc@freeuk.com> - 2026-03-26 22:36 +0000
  Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-26 16:12 -0700
    Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-27 10:55 +0000
      Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-27 13:49 +0100
      Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-27 10:51 -0700
      Re: gcc and 'include' Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-27 21:27 +0000
        Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-27 22:05 +0000
          Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-27 17:03 -0700
          Re: gcc and 'include' Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-28 05:10 +0100
          Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-28 20:37 +0300
            Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-28 18:33 +0000
              Re: gcc and 'include' antispam@fricas.org (Waldek Hebisch) - 2026-03-29 00:53 +0000
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-29 22:37 +0100
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 05:33 -0700
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-30 14:42 +0100
                Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-30 16:53 +0300
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-30 18:11 +0100
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 08:27 -0700
                Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-30 11:54 -0700
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-30 21:54 +0100
                Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-30 18:07 -0700
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-31 11:39 +0100
                Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-31 13:56 -0700
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-06 20:56 -0700
                Re: gcc and 'include' Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-06 23:12 -0700
                Re: gcc and 'include' James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-03-30 21:06 -0400
              Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-29 11:24 +0200
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-29 12:44 +0100
                Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-31 15:57 +0200
            Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 07:20 -0700
          Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 05:07 -0700
  Re: gcc and 'include' Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-27 00:25 +0000
    Re: gcc and 'include' Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-30 07:13 +0000
      Re: gcc and 'include' Andrey Tarasevich <noone@noone.net> - 2026-03-30 07:54 -0700
        Re: gcc and 'include' Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-03-31 01:46 +0000
          Re: gcc and 'include' antispam@fricas.org (Waldek Hebisch) - 2026-03-31 05:28 +0000
  Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-27 04:10 +0300
    Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-26 19:08 -0700
      Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-27 16:47 +0300
        Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-27 16:43 +0100
        Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-27 09:03 -0700
          Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-29 11:46 +0300
            Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 08:19 -0700
              Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-30 20:08 +0300
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-31 00:26 -0700
                Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-31 11:27 +0300
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-07 09:45 -0700
        Re: gcc and 'include' Andrey Tarasevich <noone@noone.net> - 2026-03-28 10:25 -0700
          Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-29 10:37 +0300
            Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-29 11:30 +0200
            Re: gcc and 'include' Andrey Tarasevich <noone@noone.net> - 2026-03-29 07:22 -0700
            Re: gcc and 'include' James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-03-29 13:56 -0400
              Re: gcc and 'include' Michael S <already5chosen@yahoo.com> - 2026-03-29 21:39 +0300
                Re: gcc and 'include' James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-03-29 20:08 -0400
                Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-30 01:58 +0100
                Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 07:59 -0700
  Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-26 19:06 -0700
  Re: gcc and 'include' Bart <bc@freeuk.com> - 2026-03-27 16:20 +0000
    Re: gcc and 'include' David Brown <david.brown@hesbynett.no> - 2026-03-27 18:07 +0100
    Re: gcc and 'include' James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-03-28 18:48 -0400
  Re: gcc and 'include' Andrey Tarasevich <noone@noone.net> - 2026-03-27 22:38 -0700
    Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-28 00:30 -0700
      Re: gcc and 'include' Andrey Tarasevich <noone@noone.net> - 2026-03-29 16:15 -0700
        Re: gcc and 'include' Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-30 00:41 -0700

csiph-web