Page 1 of 1
compiller for c++/c
Posted: Tue Dec 17, 2013 8:12 pm
by Yazimat
hi
i'm read Brokentorn tutorial and at this page
http://www.brokenthorn.com/Resources/OSDev14.html
he sais that we can compile c++ code as c code .
i wondered if i'ts possible , but i do not have the answer ,
then I ask you to
(sorry for my bad english ;/ )
Re: compiller for c++/c
Posted: Wed Dec 18, 2013 12:08 am
by neon
Hello,
Would you mind letting me know where it says that? C++ is a completely different language -- it is most certainly not possible to do what is being requested. Most C code can be compiled as C++ (although not all) -- not the other way around.
Re: compiller for c++/c
Posted: Wed Dec 18, 2013 1:40 am
by Love4Boobies
It may also be worth noting that even if your code can be compiled as either C or C++, it may not have the same meaning in both of these languages.
Re: compiller for c++/c
Posted: Sun Dec 29, 2013 5:54 pm
by Geri
i do the same in my c compiler, first i compile c++ code to c. however, not yet done with that part.
x=mylittlecat->dosomething(a,b,c,d);
translates to:
x=cats_function_dosomething(mylittlecat,a,b,c,d)
x=mylittlecat.dosomething(a,b,c,d);
translates to:
x=cats_function_dosomething(&mylittlecat,a,b,c,d)
etcetc
-object adresses must be delivered as a pointer.
-new translates to malloc, then constructor must be called.
-delete translates to free, before, destructor must be called.
-i suggest heap-created objects to translate to stack objects
-there is no object-oriented programing possible on hardware level, everything must be translated to procedural code. not a big deal.
Re: compiller for c++/c
Posted: Mon Dec 30, 2013 5:51 pm
by Griwes
Geri wrote:-new translates to malloc, then constructor must be called.
No, `new` translates to a call to the appropriate `operator new` (either global or member one, plus there's the `new[]` case), then calls constructor.
-delete translates to free, before, destructor must be called.
No; `delete` translates to a call to destructor, then calls the appropriate `operator delete` (either global or member one, plus there's the `delete[]` case).
-i suggest heap-created objects to translate to stack objects
-there is no object-oriented programing possible on hardware level, everything must be translated to procedural code. not a big deal.
What?
Re: compiller for c++/c
Posted: Mon Dec 30, 2013 6:25 pm
by skeen
LLVM allows you to emit c, instead of some assembly code.
This is just another target emit language. Can be quite useful actually.
As long as one don't plan on inspecting the output c code.
Re: compiller for c++/c
Posted: Mon Dec 30, 2013 6:55 pm
by FallenAvatar
Griwes wrote:Geri wrote:-delete translates to free, before, destructor must be called.
No; `delete` translates to a call to the appropriate `operator delete` (either global or member one, plus there's the `delete[]` case), then calls destructor.
Shouldn't the destructor be called before the delete operator?
- Monk
Re: compiller for c++/c
Posted: Tue Dec 31, 2013 4:46 am
by Griwes
D'oh; obviously.