OK, whyme_t,
I have tried inline functions, and when I disassemble my binary I see that it is still making a call to the function, rather than putting the functions code directly into the member function. So does anyone know how to force g++ to insert the inline functions code, rather than just calling the function. ???
Also, it is possible to access the data members of the class because when the actual member function is called the 'this' pointer is passed to it, then when the inline code is called (this would be different if the inline functions code was put there instead of a call), the new return address is pushed onto the stack, so the 'this' pointer is behind it, all you have to do is skip the return code and get a copy of the 'this' pointer from behind it. Then you use this as a pointer to the data member list. Of course you must know the order of the data member list, so that you dont change the wrong values, but g++ seems to alway's create this list in the order in which they are defined in the class header, obviously out of caution you should disassemble your binary just to make sure.
I really do not want to have to use inline asm, and I would rather do (3) in Tim's list, rather than a combination of (1) and (2), because g++ makes some very poor choices in code output, I know that I can write smaller and faster code than it has output, and I am willing to do extra work to do it, however I thought that putting inline in fornt of a function would force it to be put in the place where it is called, rather than just a normal call.
I know some people think that the slight overhead of calling a function is very little, and it probably is, but I want the best, and if I have to work harder then so be it.
Anyway, hopefully someone might know how to force true inline functions, if not the I guess I will be looking at the sources for g++ (the sources are freely available aren't they?) and working out what needs to be done directly in asm, even though I will be restricted to using only this version of g++ when compiling my C++ code.
Unless I check every compilers way of name mangling and edit my sources each time. :'(
Thanks.
C++ Class Objects in an OS
Re:C++ Class Objects in an OS
A Better Idea would be to just pass the 'this' pointer onto your inline function, this way you just access it like any other parameter.
So,
extern "C" inline void asmClsMember( Class* instance );
would be used like this
void Class::ClsMember()
{
asmClsMember(this);
}
and would allow you access to the class data members.
So,
extern "C" inline void asmClsMember( Class* instance );
would be used like this
void Class::ClsMember()
{
asmClsMember(this);
}
and would allow you access to the class data members.
Re:C++ Class Objects in an OS
This is just what would be best for getting at the class data members from within the extern "C" function, this is not what I want, I want to be able to prevent the second call to this function altogether.
Re:C++ Class Objects in an OS
then:
iscalledonce dw 0
code:
; if iscalledonce == 0 then
; stuff
push ax
mov ax, 1
iscalledonce, ax
pop ax
jmp exit
; if iscalledonce = 1 then exit
exit:
ret
iscalledonce dw 0
code:
; if iscalledonce == 0 then
; stuff
push ax
mov ax, 1
iscalledonce, ax
pop ax
jmp exit
; if iscalledonce = 1 then exit
exit:
ret
Re:C++ Class Objects in an OS
Tom: I think PlayOS meant he wanted the ASM function inlined into the code, and he didn't want a second call inside his C++ function. Not, the asm function to only be called once.
PlayOS: Strange, I just assumed that the inline keyword would inline the code, I'll dissemble my code and take a peek. I'm not keen on the idea of assuming that g++ create the data members in order, there must be a cleaner way.
PlayOS: Strange, I just assumed that the inline keyword would inline the code, I'll dissemble my code and take a peek. I'm not keen on the idea of assuming that g++ create the data members in order, there must be a cleaner way.