Article View: comp.windows.x
Article #38361Re: C++ and callbacks
From: Ian J Hogg
Date: Thu, 05 May 1994 16:33
Date: Thu, 05 May 1994 16:33
39 lines
2851 bytes
2851 bytes
In article <1994May5.075259.12146@reks.uia.ac.be> rgeens@wins.uia.ac.be (Ronald.Geens) writes:
>In article <CpAn8x.5I1@news.cis.umn.edu>, ianhogg@milli.cs.umn.edu (Ian J Hogg) writes:
>
>|> >|> Motif is based on C, not C++. You have to use "extern C" linkage for any of
>|> >|> your callbacks. You can't register any C++ function directly. You have to
>|> >|> write a plain C front end for anything you want to have callbacked.
>|> >
>|> >Actually the function does not have to have "extern C" linkage. It just
>|> >can't be a non-static member function.
>|> >
>|>
>|> Actually, the callback function should have "C" linkage. I have used a
>|> compiler that passed arguments differently for C linkage and C++ linkage.
>|> So, if I had a free standing function with C++ linkage and used it as a
>|> callback function, the parameters would be messed up. This is not an issue
>|> with most compilers but be aware it could be.
>|>
>|> Can anyone guess the compiler in question?
>
>I really don't have a clue! I thought the discussoin was purely theoretical !
>
>If you have worked with such a compiler, how did you use member functions as callbacks ? Or is it just not possible on such compilers ?
I wasn't even trying to use member functions as callbacks becuase you need a
normal function as glue. Once I figured out the problem I just declared all
my callbacks like this:
extern "C" void my_callback(Widget w, XtPointer client_data, XtPointer cbs)
{
/* do stuff here */
}
Anytime you are passing a pointer to a function as a parameter to a function
with "C" linkage, the passed function pointer should be declared with
"C" linkage.
--
===============================================================================
Ian Hogg ianhogg@cs.umn.edu
(612) 424-6332
Technical Details
Message-ID:
<CpC8rr.M8D@news.cis.umn.edu>Path:
arc1-ca.pugleaf.net!gmd.de!nntp.gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!convex!news.duke.edu!news-feed-1.peachnet.edu!umn.edu!milli!ianhoggReferences:
<2q67fpINNgv5@eccdb1.pms.ford.com> <CpAn8x.5I1@news.cis.umn.edu> <1994May5.075259.12146@reks.uia.ac.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103734,ad5a39011a2d3d26 X-Google-Attributes: gid103734,public X-Google-Thread: 10ba33,ad5a39011a2d3d26 X-Google-Attributes: gid10ba33,public X-Google-Thread: 109fba,ad5a39011a2d3d26 X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 1994-05-05 12:01:51 PST Newsgroups: comp.windows.x,comp.lang.c++,gnu.g++.help Path: arc1-ca.pugleaf.net!gmd.de!nntp.gmd.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!convex!news.duke.edu!news-feed-1.peachnet.edu!umn.edu!milli!ianhogg From: ianhogg@milli.cs.umn.edu (Ian J Hogg) Subject: Re: C++ and callbacks Message-ID: <CpC8rr.M8D@news.cis.umn.edu> Sender: news@news.cis.umn.edu (Usenet News Administration) Nntp-Posting-Host: milli.cs.umn.edu Organization: University of Minnesota, Minneapolis, CSci dept. References: <2q67fpINNgv5@eccdb1.pms.ford.com> <CpAn8x.5I1@news.cis.umn.edu> <1994May5.075259.12146@reks.uia.ac.be> Date: Thu, 5 May 1994 16:33:51 GMT Lines: 39