in asm i cannot call external functions written in c++ for some reason. why not? this works in c...
extern _isr0
call _isr0
..this works in c but not in c++ unless the function is named "main"
anybody know why or how to call external c++ functions?
calling external functions in c++
Re:calling external functions in c++
It is called name mangling. The C++ compiler actually changes the names of C++ functions becuase they all can be overloaded. The end result is that every function really has a unique name. You can look at what the compiler has named the function in the object code, or I believe some compilers have switches and pragmas to turn it off.
_mark
_mark
Re:calling external functions in c++
don't bother - I was hoping to stimulate you to do some research on your own as I think this is quite interesting. Just add:
extern "C" functionname /variablename
in front of it.
_mark()
extern "C" functionname /variablename
in front of it.
_mark()
Re:calling external functions in c++
so this should do it(from ASM code):
[extern "C" _clearscr]
?
[extern "C" _clearscr]
?
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:calling external functions in c++
noooo...
in assembly you still call your function [extern _name]
in c++ you import functions declared/defined in another module via extern "C" void/int/... functionname(void/int/...);
the "C" tells the C++ Compiler that this is a reference to an ordinary c function.
stay safe
in assembly you still call your function [extern _name]
in c++ you import functions declared/defined in another module via extern "C" void/int/... functionname(void/int/...);
the "C" tells the C++ Compiler that this is a reference to an ordinary c function.
stay safe
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:calling external functions in c++
yea i figured out something was wrong.
;----------------ASM CODE-------------------
[extern _function]
call _function
;----------------C++ CODE--------------------
extern "C" void function()
{
print("calling functions in c++);
}
;----------------ASM CODE-------------------
[extern _function]
call _function
;----------------C++ CODE--------------------
extern "C" void function()
{
print("calling functions in c++);
}
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:calling external functions in c++
not really:
extern "C" int yourfunction(void); -> declaration. Definition is in an other module. the linker puts the right adress there.
you call it in your function in c++ this way:
definition:
void burschi(void){
yourfunction();
}
everything clear?
extern "C" int yourfunction(void); -> declaration. Definition is in an other module. the linker puts the right adress there.
you call it in your function in c++ this way:
definition:
void burschi(void){
yourfunction();
}
everything clear?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:calling external functions in c++
and if you don't want to use extern "C", but have the C++ name used instead, you still can use "objdump -x" on your object file to discover what are the mangled names of the object you want to access...
The mangled name usually include the name (of course), the namespace (so that it translates myClass::variable into variable__Q7myClass) and the parameters type for the function (so that overloading can apply... myClass::function(void*) will be mangled in something like function__Q7myClasspv)
The mangled name usually include the name (of course), the namespace (so that it translates myClass::variable into variable__Q7myClass) and the parameters type for the function (so that overloading can apply... myClass::function(void*) will be mangled in something like function__Q7myClasspv)