This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A GCC bug related to inline?
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Bin.Cheng" <amker dot cheng at gmail dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Sun, 11 Nov 2018 12:28:11 +0100
- Subject: Re: A GCC bug related to inline?
- References: <CAHFci29WE8uH6iskLpu_1QeD=Fwa-ZbEas6xEag7Y_Kb8ZmNjQ@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Sun, Nov 11, 2018 at 02:58:26PM +0800, Bin.Cheng wrote:
> Given below simple code:
>
> inline int foo (int a) {
> return a + 1;
> }
> int g = 5;
> int main(void) {
> return foo(g);
> }
This is the standard C99 inlining behavior. inline means
provide something that can be inlined, but don't generate an external
definition. One needs to use the extern keyword in one of the TUs to emit
it. See
https://gcc.gnu.org/onlinedocs/gcc/Inline.html
https://gcc.gnu.org/gcc-4.2/changes.html
for more info. You can use -fgnu89-inline, or -std=gnu89, or gnu_inline
attribute if you are looking for the GNU inlining semantics rather than C99
one. And of course, in C++ the inlining behavior is yet different (comdat).
Jakub