www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/10/04:31:38

Xref: news2.mv.net comp.os.msdos.djgpp:5812
From: alaric AT abwillms DOT demon DOT co DOT uk (Alaric B. Williams)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to write ASM member functions?
Date: Tue, 09 Jul 1996 20:54:16 GMT
Lines: 57
Message-ID: <836945582.19057.0@abwillms.demon.co.uk>
References: <tparvine DOT 836909964 AT niksula DOT hut DOT fi>
NNTP-Posting-Host: abwillms.demon.co.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

tparvine AT niksula DOT hut DOT fi (Tero Lauri Juhani Parvinen) wrote:

>Can I write a classes member functions in asm? I would like to define them in
>a .S file, not inline. The obvious problem is that I can't just define the
>function like _function (C-style). I looked at some .o files and found
>something like _func__5MyClass_iiPc... I think the iiPc means that the
>parameters are int, int, *char, but what about that weird 5?

>Is there a simpler way to do this or does someone know what the number
>stands for?

Nyargh. Name mangling. Due to C++'s capacity to have the same function
name with different paremeters, ie:


int square(int);
float square(float);

the compiler actually considers the parameters to be part of the
name... and for backwards compatability with linkers, turns them into
that ASCII garbage after the name.

I'm not sure of the exact method used by GCC, but the reference to
MyClass in there is caused by the invisible this pointer, of type
MyClass*, being passed to your function. I guess the number is some
kind of flag or similar.

Unless any of the Real Experts can offer anything better, I would
suggest using an inlined wrapper:

extern "C" int do_my_own_thing(MyClass *this,int a,int b);

class MyClass {
	inline void do_thing(int a,int b) {do_my_own_thing(this,a,b);}
};

This is just as fast, in that it does not incur two function calls,
since the call to the real assembler stuff is inlined.

The "C" in the extern declaration means 'disable name mangling, it's
an old style C function' - perhaps you can put "C" on member
functions? That might help you.

Enjoy!

>Please reply by e-mail (tero DOT parvinen AT hut DOT fi).
>Thanks in advance.

I'll post it as well, in case any of the experts can shed light.


--
I have become... Comfortably numb...

Alaric B. Williams Internet : alaric AT abwillms DOT demon DOT co DOT uk
<A HREF="http://www.hardcafe.co.uk/Alaric/">http://www.hardcafe.co.uk/Alaric/</A>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019