This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]