c/4101: gcc 2.95.4 compiles bad code with nested static functions

cristiano chitty@libero.it
Fri Aug 24 03:26:00 GMT 2001


> 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 */
> }





More information about the Gcc-bugs mailing list