When I needed to write C code, I learnt ASM instead, because it is more interesting and you can still do everything you need to.
Now, I will soon have a project that requires me to write C++. However, I do not want to learn it and do not have an IDE or compiler.
Writing C code in ASM is possible. How can I write C++ code in ASM?
EDIT: I don't mean inline. I mean, make a module in ASM with objects and methods etc that are compatible with other modules written in C++
I can't see that one happening in a hurry, the sheer compexity of the overhead will knock you over. If you have a strong enough stomach, suspend the sensible stuff you have learnt and see if you can master enough of this puke to get the app up and running. You can then cheat and write the guts of it in C or perhaps in MASM modules if you cannot stomach much more of it.
Puke? Guts? My, my, such language! (http://en.wikipedia.org/wiki/Eliza) :green.
You can have some luck writing modules in asm if you target only a single compiler and know exactly what rules it uses for stuff like the 'this' pointer and name decoration. It might be a better choice to write the asm modules as C callable, and then use them from a C++ wrapper though.
Either way you will not get the benefits of stuff like templates this way of course :U.
Hi Aero,
Which C++ compiler are you going to use?
I would prefer not to use any C++ compiler at all, and just write C++ compatible code in ASM, but as hutch said the overhead will probably kill me.
I did not connect the idea properly, (sick in the stomach at the prospect :bg ) but the idea is basically that C++ as against C is a lot more complicated under the hood so you are better off to learn its basics than try and emulate it in asm. Look at it on the bright side, it should get your REAL C up to scratch in a hurry. :toothy
Hi Aero,
there is a paper by Agner Fog regarding calling conventions on different compilers, you'll find it useful. And don't worry too much about the "complexity", it ain't so bad really... :wink
You mean that object modules are specific to each compiler? Scrap this. What is the best free compiler around? I know two compilers: the VC++ toolkit one and GCC.
It depends how "C++"-ified you want to be :bdg If you just want to use objects with simple inheritence and virtual functions then it's not so difficult.
Compatibility between compilers is next to none :P
If you have to write in C++, I presume it will be so that someone can later access/read/understand/modify the code. Which means you will probably have to do actual (urgh, dirty dirty!!) C++.
There are numerous C++ compilers, many of which are 'free' - it's just a case of whichever suits you best. Searchy :wink
Hi Aero,
Talking about C++ compilers, have a look also at the free Digital Mars C/C++ compiler package.
You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.
[uote author=QvasiModo link=topic=1693.msg13133#msg13133 date=1116618085]
You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.
Quote
Argh! Total jargon!
I have decided that I may as well learn C and then C++, if I want to be respected as a decent programmer. My learning experience with programming as been quite good I think: starting with VB to learn the basics of programming, then jumping into ASM to learn how the computer works, and now when I learn C I can apply both low level optimisation techniques and high level programming style.
So, back to my question, which free C/C++ compiler is the best? Also, if I use a C++ compiler to compile C code, will it be more bloated than if I used an ordinary C compiler?
Hi Aero,
Good C++ compilers : MS VC++ Toolkit 2003 and Digital Mars. ( Probably also GCC which I never tried )
C compilers : PellesC and the other same C/C++ compilers.
Check out ATC and ObjAsm32 oopasm implementations, both are C++ compatible sets of masm macros :)
Bah @ you guys :)
Quote from: AeroASM on May 20, 2005, 07:56:04 PM
[uote author=QvasiModo link=topic=1693.msg13133#msg13133 date=1116618085]
You could instead write a C compatible library. Then do some wrapper classes for C++ using inlined methods. That would work for all C++ compilers.
Quote
Argh! Total jargon!
Sorry, I'll elaborate a bit here... this was my suggestion:
Write an ordinary .lib or .dll library in ASM, or you always had. This library will be compatible with C as MASM uses the same calling conventions.
Then write a C++ class that does nothing but call the ASM functions. The "methods" (functions) for that class should be "inlined" (a C++ mechanism that works in a similar way as a MASM macro). This gives the C++ look and feel to your ASM library, but adds no overhead.
In any case you'll find it convenient to learn the basics of C and C++ to write a good library for those languages... even if you implement it in assembly, one day you'll have to write the .h files! :wink
Good luck in your project! :U
Quote from: AeroASM on May 20, 2005, 12:53:39 PM
I would prefer not to use any C++ compiler at all, and just write C++ compatible code in ASM, but as hutch said the overhead will probably kill me.
If your just building small applications in C++ the name decorating alone that the compiler generates is verbose. Make a C++ compiler write an ASM file for you and take a good look at it. Thats the kind of stuff you would probably have to write to accomplish what your trying to do, and it would get complicated very quickly.
What exactly is your end goal? Just doing a C++ progect (for a class or job), or learning C++, or doing something specific and small that'd be easier to do in C++ than ASM.
If your doing it for a class or project, obviously you gotta learn c++ (probably shouldn't of even asked this one)
If just for learning C++ than there are some tutorials i can point you to to learn.
If doing something specific in C++ and doing rest in ASM (or vise versa) then making a DLL in one of the two languages and call an exported function and have it do what you need it to in that specific language.
Which do you need?
Wow is it just me and Homer that understood what AeroASM wants?
There are two complete frameworks to do all the hard work for you (at no cpu-cycles cost!) : OA32 and ATC.
Get them from
OA32 - http://objasm32.tripod.com/
ATC - http://www.ultrano.com/ilix/
Writing C++ classes in them is easy . In ATC I accented on ease of use, but the documentation and available object library are not complete/big. In OA32 it's the other way around (and is more powerful too) .
But in the end, they both do the same job - enabling interfacing with C++ objects - exactly what you said you need :) .
Here's an example of ATC vs C++ code:
class Derived : public BaseOne{
long x;
long y;
void Func1(long a);
virtual void Func2(long b);
};
...
Derived* obj1;
obj1 = new Derived;
obj1->x = 10;
obj1->Func1(7);
obj1->Func2(8);
delete obj1;
class Derived,BaseOne,C++ compatible
long x
long y
void Func1 : a
virtual Func2 : b
endclass
...
local obj1:DWORD
mov obj1,new(Derived)
;mov ecx,obj1 ; (actually can be skipped, since "new" gives the pointer in ECX too
mov [ecx].Derived.x,10
;-------[ style 1 ]--------------------\
set obj1 as Derived
pcall obj1.Func1,7
pcall obj1.Func2,8
;----------------------------------------/
;-------[ style 2 ]----------------------------\
;icall obj1,Derived,Func1,7
;icall obj1,Derived,Func2,8
;------------------------------------------------/
; (N.B: two more styles available, to select from :) )
delete obj1
Both ATC and OA32 need MASM (only its macros are powerful enough to make complex OOP possible).
What, exactly, is this project going to be?