Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: gcc and 'include' Date: Thu, 26 Mar 2026 16:12:47 -0700 Organization: None to speak of Lines: 40 Message-ID: <87ikaiw5g0.fsf@example.invalid> References: <10q4ceb$38i2d$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Thu, 26 Mar 2026 23:12:48 +0000 (UTC) Injection-Info: dont-email.me; posting-host="2a8a38369431aadba7895462cd59e88a"; logging-data="3440969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FJNINDTEH2XYvkSqwpTJF" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:B30tRIdETtcIiNDIcWRz+5Pvu3o= sha1:EQN/3Jo/mT393VbJ2Yy+LMx2WLI= Xref: csiph.com comp.lang.c:397207 Bart writes: > Take this program: > > #include > > inline int F(){return rand();} > > int main(void) { > return F(); > } > > This compiles fine with gcc using -O1 -O2 -O3. > > But compile without optimising, and it fails to link as it can't find > a function 'F'. > > Is it supposed to behave like that? I assume no discrete function F is > being generated because of the 'inline' attribute, but you'd think it > would ignore that if inlining wasn't enabled. > > It compiles fine with or without 'inline' using tcc and bcc (my product). > > Clang fails too, but clearly only because it has to duplicate gcc's > behaviour for drop-in compatability, even if it is crass. > > (This is the actual program: > https://web.archive.org/web/20010127204000/http://www.bagley.org/~doug/shootout/bench/lists/lists.gcc) I don't have an answer to your question, but defining F as "static inline" makes the program work. You can also do this: inline int F(); int F(){return rand();} (Unless you're using a C23 compiler, I suggest "int F(void)" rather than "int F()".) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */