PDA

View Full Version : Combining different languages



MethodMan
10-04-2002, 06:20 PM
Ive never heard anyone mention this, so I dont even know if its possible. Is there anyway you can combine different programming languages such as C, C++, Java, assmebler to work together at all?

I can see assembler being useful with C or C++.

If so, can you provide an example to why, or how it would be done.

Thanks

TechWins
10-04-2002, 06:41 PM
Yes, you can use assembly with c/c++. I think you type in some special command then you put your assembly code there. I'm not really sure how you do it, except that it's not that difficult to include it and that you can actually include it. Try doing a search for it on the board; I'm sure you'll find info about it.

Eibro
10-04-2002, 06:51 PM
#include <iostream>

int main(int argc char *argv[])
{
asm
{
xor eax, eax
};
std::cout << "Wasn't that fun!" << std::endl;
return 0;
}

face_master
10-04-2002, 08:36 PM
that didn't work

Sentaku senshi
10-04-2002, 09:00 PM
What compiler are you useing?

face_master
10-04-2002, 11:42 PM
MSVC++ 6.0

TechWins
10-04-2002, 11:52 PM
using namespace std;


If you didn't include that, that might be your reason why it didn't compile.

Btw, I've heard some where that it may vary on different compilers for what you use for your declaration of using asm.

EDIT: n/m That doesn't completely solve the problem, but that still should have been included.

Shade
10-05-2002, 02:48 AM
the syntax for asm isn't always the same (I think the C++ standard includes a keyword asm, but every compiler has its own syntax)

for VC++

__asm {
xor eax, eax
}

or
__asm xor eax,eax

Look in the MSDN :)


But there are more possibilities to combine different languages!

For example with COM.
Or very simple: with DLLs - because you can write a DLL in nearly every language...

It is common to use a Visual Basic frontend, and a C DLL as backend :)

It is important, that you have an interface which combines the languages. For example DLLs, COM or even .NET!

adrianxw
10-05-2002, 03:07 AM
I frequently write libraries and .DLL's in Object Pascal using Borlands Delphi product - their database stuff is so much easier to use than MS's.

As long as you are careful with calling standards, etc. most languages compile to object files which can be linked together by a suitable linker to form an executable.

Shiro
10-05-2002, 05:56 AM
Yes it is possible to combine languages. A very important thing is understanding of the linker you are using. A lot of compilers, for whatever language, support a standard object-file format to which they can compile. With a linker which understands this format, you can combine it all.

Combing languages is done a lot, since most languages have something they are better in than others. So to make efficient software, you could consider to use the advantages the individual languages offer.

Java is a nice language, it is not very useful in real-time systems, but is is nice for creating for example a GUI. So for a real-time system with a GUI you could consider to use Java for the GUI and C++ for the real-time parts and if necessary use assembly to do the real low level stuff. If your application also has a lot of math to do, you could consider also program some parts in a functional language like Haskell.