From: Rechberger Markus <mrechberger@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Problem with pointer to external function
Date: Fri, 1 Jul 2005 12:54:37 +0200 [thread overview]
Message-ID: <d9def9db05070103545325ee64@mail.gmail.com> (raw)
In-Reply-To: <20050701103026.GA2965@paktahn.black.cat>
Hey,
I'd write it like that:
main.c
----
#include <stdio.h>
extern void cb();
void (*callback)()=cb;
int main (int argc, char** argv){
callback();
return(0);
}
defhandler.c
----
void cb()
{
printf("handler\n");
}
$ gcc main.c defhandler.c -o test
$ ./test
handler
Markus
On 7/1/05, leslie.polzer@gmx.net <leslie.polzer@gmx.net> wrote:
> Hello list,
>
> why do it get the segfault below? What's wrong?
>
>
> [sky@paktahn ~/code/cbtest]% cat main.c
> #include <stdio.h>
>
> typedef void (*callback)();
>
> extern callback cb;
>
> int
> main (int argc, char** argv)
> {
> cb();
>
> return(0);
> }
>
> [sky@paktahn ~/code/cbtest]% cat defhandlers.c
> void cb()
> {
> }
>
> [sky@paktahn ~/code/cbtest]% gcc main.c defhandlers.c -ggdb
> [sky@paktahn ~/code/cbtest]% gdb ./a.out
> GNU gdb 6.3
> Copyright 2004 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB. Type "show warranty" for details.
> This GDB was configured as "i686-pc-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
>
> (gdb) run
> Starting program: /home/sky/code/cbtest/a.out
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x5de58955 in ?? ()
> (gdb) bt full
> #0 0x5de58955 in ?? ()
> No symbol table info available.
> #1 0x08048367 in main (argc=1, argv=0xbffff634) at main.c:10
> No locals.
> (gdb)
>
>
> Regards,
>
> Leslie
>
> --
> PGP-KID: 0x52D70289
>
>
>
next prev parent reply other threads:[~2005-07-01 10:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-01 10:30 Problem with pointer to external function leslie.polzer
2005-07-01 10:54 ` Rechberger Markus [this message]
2005-07-01 11:17 ` Steve Graegert
2005-07-01 16:41 ` Glynn Clements
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=d9def9db05070103545325ee64@mail.gmail.com \
--to=mrechberger@gmail.com \
--cc=linux-c-programming@vger.kernel.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 NNTP newsgroup(s).