Re: question about `static inline` functions in header files

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: question about `static inline` functions in header files
Date: 2022-07-22 03:08:54
Message-ID: CAEG8a3JSEQvtZWyCMQH6GaRJHpBfhygQZJHt9A8Ec0VCgbqqdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Ok, thanks for the clarification.

On Fri, Jul 22, 2022 at 11:03 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Junwang Zhao <zhjwpku(at)gmail(dot)com> writes:
> > I notice that there are lots of *static inline functions* in header files,
> > the header file's content will go into each translation unit at preprocess
> > phase, that means all the c file including the header will have a copy
> > of the static inline function.
>
> We are assuming that the compiler will not emit unused static functions.
> This has been default behavior in gcc for ages. If you're unfortunate
> enough to have a compiler that won't do it, yes you're going to have a
> bloated binary.
>
> > IMHO, the header files should only include the inline function's declaration,
> > and the definition should be in c files.
>
> Then it couldn't be inlined, defeating the purpose.
>
> regards, tom lane

--
Regards
Junwang Zhao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-07-22 03:10:04 Re: Remove useless arguments in ReadCheckpointRecord().
Previous Message Fujii Masao 2022-07-22 03:07:28 Re: postgres_fdw: Fix bug in checking of return value of PQsendQuery().