question about `static inline` functions in header files

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: question about `static inline` functions in header files
Date: 2022-07-22 02:17:00
Message-ID: CAEG8a3L3GTFq6F07cx+Y8qkX_CPTTOQu-27Gzxbi9b_S3s_1fw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

The inline keyword is a hint for compiler to inline the function, if the
compiler does inline the function, the definition could be optimized out
by the compiler, but if the *inline function* can not be inlined, the function
will reside in each of the translation units that include the header file, which
means the same static function compiled multiple times and may waste
some space?

IMHO, the header files should only include the inline function's declaration,
and the definition should be in c files.

I am not sure why this kind of coding style came along, appreciate if
some one can give me some clue, thanks :)

--
Regards
Junwang Zhao

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2022-07-22 02:50:14 Re: Remove useless arguments in ReadCheckpointRecord().
Previous Message Kyotaro Horiguchi 2022-07-22 02:09:22 Re: [PATCH v1] eliminate duplicate code in table.c