This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/4101: gcc 2.95.4 compiles bad code with nested static functions
- To: <alessandro_amici at telespazio dot it>, <chitty at libero dot it>,<gcc-bugs at gcc dot gnu dot org>, <gcc-prs at gcc dot gnu dot org>, <nobody at gcc dot gnu dot org>,<neil at gcc dot gnu dot org>, "Bernd Schmidt" <bernds at redhat dot com>
- Subject: Re: c/4101: gcc 2.95.4 compiles bad code with nested static functions
- From: "cristiano" <chitty at libero dot it>
- Date: Fri, 24 Aug 2001 12:26:33 +0200
- References: <Pine.LNX.4.33.0108232010470.13997-100000@host140.cambridge.redhat.com>
> Basically, f1 is treated as a local variable, and you
> can't keep pointers to those across multiple calls to a function either.
>
>
> Bernd
thank you.
i've now declared f1 and f2 as STATIC.
the problem remains... if they're now static, the code should be valid now,
shouldn't it??
(cristiano)
---
tell me is something illuding you, sunshine?
------------------------- www.neuromante.net *
here the code, again.
> /* this must do a certain thing only the 1st time,
> but we don't want a check as if (first_time) {do},
> so we use a function pointer that the first time
> does, the others just returns.
> */
> void loop(void)
> {
> static void f1(void);
> static void f2(void);
> static void (*f)(void) = f1;
>
> static void f2(void) { } /* this is empty */
>
> static void f1(void)
> {
> /* ... do something */
> f=f2; /* the problem is HERE */
> }
>
> (*f)(); /* do something only the first time */
> }