Menu

#3877 Duplication of static objects in inline functions

open
nobody
None
other
5
2025-09-04
2025-09-03
No

In current trunk (but AFAIK, this is not a new issue), static objects in inline functions get duplicated:

static inline int f(void)
{
    static int i;
    return(i++);
}

int g(void)
{
    return(f());
}

int h(void)
{
    return(f());
}

We get three copies of i, one used by the inlined call in g, one used by the inlined call in h, one for use by calls to f that are no inlined.

However, according to the c standard, we should only have one copy of i, since logically, there is only one definition of f (per translation unit).

The bug also happens if f is not static (which SDCC will allow without complaint, despite the use of static objects in non-static inline functions being a C2Y feature that was a constraint violation up to C23 - I'll file a separate bug for that).

Related

Bugs: #3878

Discussion

  • Konstantin Kim

    Konstantin Kim - 2025-09-04
     
    • Philipp Klaus Krause

      No; that one is about static inline functions, this one is about static objects inside inline functions (basically, the keyword static has three different meanings in C, depending on the context where it is used, these are two of them).

       

      Last edit: Philipp Klaus Krause 2025-09-04

Log in to post a comment.

Monday.com Logo