Getting the address of a function in C++ with any egcs
ABalmosan@orga.com
ABalmosan@orga.com
Wed Mar 31 23:54:00 GMT 1999
If the statment:
&x.test1
gives an address how do I pass this address to a function?
printf warns the &x.test1 is not a pointer and if you try the following
code:
---------------------------
#include <stdio.h>
class X {
public:
void test();
virtual void test1();
};
class Y: public X {
public:
void test1();
};
void X::test()
{
printf("hallo.x\n");
}
void X::test1()
{
printf("hallo1.x\n");
}
void Y::test1()
{
printf("hallo1.y\n");
}
void main()
{ X x;
Y y;
printf("%p\n", &x.test1);
printf("%p\n", &y.test1);
#if 0
if (&x.test1 == &y.test1) {
printf("they are equal\n");
} else {
printf("they are not equal\n");
}
#endif
}
-------------------------------
the addresses of x.test1 and y.test1 are equal which can not be because
they are two different functions.
I don't see a way how to get the actuall address of a function. Even when I
define a type:
typedef void (*func_t)();
func_t tx=&x.test1;
the egcs says:
y.cc:40: object missing in `X::test1()'
y.cc:40: warning: converting from `void (X::*)()' to `void (*)()
Regards,
Aurel Balmosan
Nathan Sidwell <nathan@acm.org> on 22.03.99 12:54:37
Please respond to nathan@cs.bris.ac.uk
To: Aurel Balmosan/Paderborn/ORGA
cc: egcs-bugs@cygnus.com
Subject: Re: Getting the address of a function in C++ with any egcs
ABalmosan@orga.com wrote:
>
> Hi all,
> I have a problem getting the address of a C++ function with the egcs
(any
> version). With the gcc-2.7.2.3 it was possible.
> y.cc: In method `void X::test()':
> y.cc:17: warning: assuming & on `(*this) .* X::test()'
> y.cc:17: cannot convert `X::test()' from type `void (X::*)()' to type
`char
> *'
> --------------
> I noticed the warnings but '&' does not change the error 'cannot convert
> ...'
You need the `&' if you want conformant source code (C++ doesn't allow
implicit
`&' to generate ptr to member function).
>
> When will it be possible to get the address of a function with egcs? (I
> check egcs-1.1.1 on linux too with no success)
It is possible to get the address of a function with egcs. What you're
trying
to do is convert a pointer to member function into pointer to char. This is
not
allowed by the language. gcc 2.7.2.3 implemented this when the language was
in
a state of flux.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk
More information about the Gcc-bugs
mailing list