C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The dreaded question
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
caustik
Guest





PostPosted: Wed Jul 02, 2003 10:11 pm    Post subject: The dreaded question Reply with quote



I don't care if its bad C++, I really dont. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

I have the perfect way to do it right here, but i'm having troubles
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

caustik

// ******************************************************************
// * Take THIS C++ !!
// ******************************************************************
template <class BaseClass> inline void *MFPtoFP( void
(BaseClass::*pMemFunc)(void) )
{
union
{
void BaseClass::*pMemFunc;
void *pFunc();
}
ThisConv;

ThisConv.pFunc = pMemFunc;

return ThisConv.pFunc;
}


Back to top
Victor Bazarov
Guest





PostPosted: Wed Jul 02, 2003 10:23 pm    Post subject: Re: The dreaded question Reply with quote



"caustik" <caustik (AT) nospam (DOT) com> wrote...
Quote:
I don't care if its bad C++, I really dont. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

A pointer to member cannot be converted to void*. Period. It's
not "bad C++", it's "not C++". Such conversion does not exist
in C++.

Quote:
I have the perfect way to do it right here, but i'm having troubles

So, if you're "having troubles", how can it be "perfect"?

Quote:
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

There is no way.

Now, let me ask you a question. Why do you think you need that?

Quote:

caustik

// ******************************************************************
// * Take THIS C++ !!
// ******************************************************************
template <class BaseClass> inline void *MFPtoFP( void
(BaseClass::*pMemFunc)(void) )
{
union
{
void BaseClass::*pMemFunc;
void *pFunc();

You could declare this as

void (*pFunc)();

but it's _not_ going to solve the conversion problem, trust me.
It will probably get rid of the "casting error", as you put it,
but it's not going to give the right answer.

Quote:
}
ThisConv;

ThisConv.pFunc = pMemFunc;

return ThisConv.pFunc;
}



Victor



Back to top
Cy Edmunds
Guest





PostPosted: Wed Jul 02, 2003 10:27 pm    Post subject: Re: The dreaded question Reply with quote



"caustik" <caustik (AT) nospam (DOT) com> wrote

Quote:
I don't care if its bad C++, I really dont.

Well, then, I don't care if it works. I really don't.

lol

See Victor's answer.

Cy



Back to top
caustik
Guest





PostPosted: Wed Jul 02, 2003 10:48 pm    Post subject: Re: The dreaded question Reply with quote


Quote:
A pointer to member cannot be converted to void*. Period. It's
not "bad C++", it's "not C++". Such conversion does not exist
in C++.

Damn, you know that I stated I dont care. There are tricks to do it,
and I dont give a flying crap if they arent technically legal.

Quote:
I have the perfect way to do it right here, but i'm having troubles

So, if you're "having troubles", how can it be "perfect"?

Well, fool, the method is "perfect" because it works 100% of the time
in my program. I happen to know the system that my program is compiled
and executed on, so I can take advantages of facts about that system.

I suppose I am ignorant to dare to optimize my program.

Quote:

because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

There is no way.

Bullshit, I did it already.

Quote:

Now, let me ask you a question. Why do you think you need that?

Let me rephrase your question: Why do you [smart ass remark] need that?

The reason is that I have a massive array of generic pointers to functions,
and their respective "Wrapper" functions which are called when the binary
code for these intercepted functions is executed. The problem is that some
of these functions are "__thiscall", and the intercepted code must take this
into account.

Believe it or not, not everbody's C++ program can be efficient while obeying
every single anal object oriented design rule on the planet. I am
interfacing
with already-compiled C++ code, so it takes some "Hacks" to get it working
efficiently and without looking like utter garbage.

After several years of reading this newsgroup, I've noticed there is some
sort
of deep rooted psychological problem with some of you guys. You'd sooner
spend 30 minutes typing a lengthy "I'm above everybody" post to respond to
peoples slightly offtopic or anal-incomplatible questions, instead of
posting a
quick solution and saying "note that this is a hack". Its horrible.



Back to top
caustik
Guest





PostPosted: Wed Jul 02, 2003 10:53 pm    Post subject: Re: The dreaded question Reply with quote

P.S. This works *Pefectly* (on my x86/win32 system, which is all i'm
targetting) :

// ******************************************************************
// * Take THIS C++ !!
// ******************************************************************
template <class BaseClass, typename MFT> inline void *MFPtoFP( MFT pMemFunc)
{
union
{
MFT pMemFunc;
void (*pFunc)();
}
ThisConv;

ThisConv.pMemFunc = pMemFunc;

return ThisConv.pFunc;
}


Back to top
Andre Kostur
Guest





PostPosted: Wed Jul 02, 2003 11:16 pm    Post subject: Re: The dreaded question Reply with quote

"caustik" <caustik (AT) nospam (DOT) com> wrote in
news:bdvnpi$hg8$1 (AT) eeyore (DOT) INS.cwru.edu:

Quote:
P.S. This works *Pefectly* (on my x86/win32 system, which is all i'm
targetting) :

Since you know your target platform, why don't you take your question over
to a newsgroup that caters to your target platform (and since you
apparently already know that it cannot be done in Standard C++)? I'd
suggest one of the newsgroups on Microsoft's news server probably being the
most topical.

Back to top
E. Robert Tisdale
Guest





PostPosted: Wed Jul 02, 2003 11:28 pm    Post subject: Troll Alert: The dreaded question Reply with quote

Something that calls itself caustik wrote:

Quote:
I don't care if its bad C++, I really don't. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

I have the perfect way to do it right here, but I'm having troubles
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

caustik

// ******************************************************************
// * Take THIS C++ !!
// ******************************************************************
template <class BaseClass> inline void *MFPtoFP( void
(BaseClass::*pMemFunc)(void) )
{
union
{
void BaseClass::*pMemFunc;
void *pFunc();
}
ThisConv;

ThisConv.pFunc = pMemFunc;

return ThisConv.pFunc;
}

This is an obvious troll. Please ignore it.


Back to top
Default User
Guest





PostPosted: Wed Jul 02, 2003 11:36 pm    Post subject: Re: The dreaded question Reply with quote



caustik wrote:
Quote:


Damn, you know that I stated I dont care. There are tricks to do it,
and I dont give a flying crap if they arent technically legal.


Yeah . . . I going to need you to go into my killfile. Yeah . . . move
all the way to the back. Thanks, that'll be great.




Brian Rodenborn

Back to top
Michael Furman
Guest





PostPosted: Wed Jul 02, 2003 11:48 pm    Post subject: Re: The dreaded question Reply with quote


"Howard Hinnant" <hinnant (AT) metrowerks (DOT) com> wrote

Quote:
In article <bdvl9r$cgp$1 (AT) eeyore (DOT) INS.cwru.edu>, caustik
[email]caustik (AT) nospam (DOT) com[/email]> wrote:
[...]
If you really want to do this, C++ offers a far easier route. You can
convert anything to anything, with zero computational cost:

#include <vector
#include #include
template inline
T just_do_it(const U& u)
{
return *(T*)(&u);
}

int main()
{
std::vector just_do_it<std::vector(std::list<std::string>());
}

... not that I'm recommending it mind you. Here's the rope ...

I would recomment much more safe and effective solution to "convert"
anything
to void pointer:

#define convert_to_pointer(argument) ((void *)0)

regards,
Michael Furman





Back to top
David White
Guest





PostPosted: Thu Jul 03, 2003 12:39 am    Post subject: Re: Troll Alert: The dreaded question Reply with quote

E. Robert Tisdale <E.Robert.Tisdale (AT) jpl (DOT) nasa.gov> wrote

Quote:
This is an obvious troll. Please ignore it.

I don't know if it's a troll or not, but it clearly wasn't obvious to all
those who answered the question.

Is it just the email address that makes it a troll?

Just wondering.

David




Back to top
Jack Klein
Guest





PostPosted: Thu Jul 03, 2003 1:21 am    Post subject: Re: The dreaded question Reply with quote

On Wed, 2 Jul 2003 15:48:37 -0700, "caustik" <caustik (AT) nospam (DOT) com>
wrote in comp.lang.c++:

Quote:

A pointer to member cannot be converted to void*. Period. It's
not "bad C++", it's "not C++". Such conversion does not exist
in C++.

Damn, you know that I stated I dont care. There are tricks to do it,
and I dont give a flying crap if they arent technically legal.

I have the perfect way to do it right here, but i'm having troubles

So, if you're "having troubles", how can it be "perfect"?

Well, fool, the method is "perfect" because it works 100% of the time
in my program. I happen to know the system that my program is compiled
and executed on, so I can take advantages of facts about that system.

If you know, and don't care, that's is not legal C++, and yet you post
it in comp.lang.c++ and display an insulting attitude to those who
tell you is it not legal C++, you are the one with the psychological
problem.

*PLONK*

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

Back to top
E. Robert Tisdale
Guest





PostPosted: Thu Jul 03, 2003 1:35 am    Post subject: Re: Troll Alert: The dreaded question Reply with quote

David White wrote:

Quote:
E. Robert Tisdale wrote:

This is an obvious troll. Please ignore it.

I don't know if it's a troll or not,
but it clearly wasn't obvious to all those who answered the question.

Is it just the email address that makes it a troll?

Just wondering.

I was simply expressing my opinion.
I look for the typical signs:

1. a troll handle
caustik,
2. a forged or disposable email account
nospam.com,
3. an emotionally provocative subject
The dreaded question
4. the original poster does not participate in the discussion
(except, possibly, to abuse the respondents)

There is seldom a good reason why a legitimate post
to a technical newsgroup like comp.lang.c++
should evoke a strong emotional response in any subscriber.
If it does, you should suspect a troll.
Real people use real names and post from legitimate ISPs.
Trolls use handles and post from disposable email accounts
or just forge the the address so you can't trace them.
Be vigilant. Learn to recognize trolls
and don't respond to them.


Back to top
tom_usenet
Guest





PostPosted: Thu Jul 03, 2003 9:55 am    Post subject: Re: The dreaded question Reply with quote

On Wed, 2 Jul 2003 15:11:09 -0700, "caustik" <caustik (AT) nospam (DOT) com>
wrote:

Quote:
I don't care if its bad C++, I really dont. I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

sizeof memfunptr on VC++ can be 4, 8 or 12 (and possibly bigger?),
depending on the function and class in question. Size of void(*)() is
4. As you can see, a non-lossy conversion is impossible in general.

Quote:

I have the perfect way to do it right here, but i'm having troubles
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

It isn't perfect even if you fix it - if the classes involved have
virtual base classes, or you use multiple inheritence, then you'll get
a crash. If they don't, you may be ok with your current version, but
it may of course start crashing next time you upgrade, or if you
switch to another compiler.

Tom

Back to top
Alexander Terekhov
Guest





PostPosted: Thu Jul 03, 2003 10:32 am    Post subject: Re: The dreaded question Reply with quote


caustik wrote:
Quote:

I don't care if its bad C++, I really dont.

Yeah. But it *might* not work even on "x86/win32 system", believe me.

Quote:
I need to convert from
a member function pointer to a "void*" with zero computational
overhead.

Stay away from "void*".

Quote:

I have the perfect way to do it right here, but i'm having troubles
because if the member function pointer i pass to the function is
not void with no params, I get a casting error.

Any ideas how to do this?

Sure. http://groups.google.com/groups?selm=3DD1805B.2D95B66D%40web.de

regards,
alexander.

Back to top
Alexander Terekhov
Guest





PostPosted: Thu Jul 03, 2003 11:18 am    Post subject: Re: The dreaded question Reply with quote


Default User wrote:
[...]
Quote:
Yeah . . . I going to need you to go into my killfile. Yeah . . . move
all the way to the back. Thanks, that'll be great.

I'm just curious: how BIG is your killfile? Well, I'm asking because
I'd be interested to buy a copy of it... if it's "big enough", so to
speak. ATTENTION: this "offer" is valid for all c.l.c++'s "plonkers"
from The United States (only) and will last until the end of The 226th
Independence Day (in all US time zones... uhmm, except Alaska, Hawaii,
and Samoa, sorry for that). Hurry up and act NOW! I need _only_one_
copy -- the BIGGEST one.

regards,
alexander.

P.S. Default, did you appreciate "the e-greetings" from Berlin City
Dump... did it arrive yet?

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.