public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Bernd Schmidt <bernds@redhat.com>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: Re: c/4101: gcc 2.95.4 compiles bad code with nested static functions
Date: Thu, 23 Aug 2001 12:16:00 -0000 [thread overview]
Message-ID: <20010823191603.21714.qmail@sourceware.cygnus.com> (raw)
The following reply was made to PR c/4101; it has been noted by GNATS.
From: Bernd Schmidt <bernds@redhat.com>
To: <chitty@libero.it>
Cc: <gcc-gnats@gcc.gnu.org>, <alessandro_amici@telespazio.it>,
<nobody@gcc.gnu.org>, <gcc-prs@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: c/4101: gcc 2.95.4 compiles bad code with nested static functions
Date: Thu, 23 Aug 2001 20:15:16 +0100 (BST)
(I currently can't access the gnatsweb page for some reason, otherwise
I'd have closed this. If gnats works for someone, please close...).
> /* 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)
> {
> void f1(void);
> void f2(void);
> static void (*f)(void) = f1;
>
> void f2(void) { } /* this is empty */
>
> void f1(void)
> {
> /* ... do something */
> f=f2; /* the problem is HERE */
> }
>
> (*f)(); /* do something only the first time */
> }
This isn't actually valid. The line
> static void (*f)(void) = f1;
constructs a trampoline on the current stack of the function loop, and
once you've exited from that function, the contents of the stack are
no longer valid. Basically, f1 is treated as a local variable, and you
can't keep pointers to those across multiple calls to a function either.
Bernd
next reply other threads:[~2001-08-23 12:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-23 12:16 Bernd Schmidt [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-08-23 12:42 neil
2001-08-23 11:26 chitty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010823191603.21714.qmail@sourceware.cygnus.com \
--to=bernds@redhat.com \
--cc=gcc-prs@gcc.gnu.org \
--cc=nobody@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).