Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: gcc and 'include' Date: Thu, 26 Mar 2026 19:06:28 -0700 Organization: A noiseless patient Spider Lines: 52 Message-ID: <861ph63u1n.fsf@linuxsc.com> References: <10q4ceb$38i2d$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Fri, 27 Mar 2026 02:06:31 +0000 (UTC) Injection-Info: dont-email.me; posting-host="606171d349eb5423921af05ed404581c"; logging-data="3543807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KFpH6aQC6n32+BP7VPO5GeTWC967D/wk=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:zo5MTnRfmE4CtQNlp0KkX1AlaWo= sha1:mFQ4sLg07PV41WS2hh1KILYWmJQ= Xref: csiph.com comp.lang.c:397210 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? The C standard allows the observed behavior. Here is a different formulation: /* ??? */ inline int F(); int main(void){ return F(); } inline int F(){ return 0; } This program shows (under gcc, in my environment) ths same behavior as what you describe. A conforming implementation may choose to compile and run the program without problem, or it may choose to fail the program because there is no definition of F() with external linkage (and that statement is true regardless of optimization setting). If the comment line (with question marks) is replaced by either extern or static then the program links and runs without problem.