compiller for c++/c

Programming, for all ages and all languages.
Post Reply
Yazimat
Posts: 9
Joined: Thu May 09, 2013 8:47 am

compiller for c++/c

Post 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 ;/ )
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: compiller for c++/c

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: compiller for c++/c

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: compiller for c++/c

Post 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.
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: compiller for c++/c

Post 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?
Last edited by Griwes on Tue Dec 31, 2013 4:47 am, edited 1 time in total.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
skeen
Member
Member
Posts: 59
Joined: Tue Sep 27, 2011 6:45 am
Location: Denmark

Re: compiller for c++/c

Post 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.
// Skeen
// Developing a yet unnamed microkernel in C++14.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: compiller for c++/c

Post 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
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: compiller for c++/c

Post by Griwes »

D'oh; obviously.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Post Reply