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 ;/ )
compiller for c++/c
Re: compiller for c++/c
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.
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: compiller for c++/c
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 ]
[ Project UDI ]
Re: compiller for c++/c
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.
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
http://users.atw.hu/gerigeri/DawnOS/download.html
- Griwes
- 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
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.Geri wrote:-new translates to malloc, then constructor 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).-delete translates to free, before, destructor must be called.
What?-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.
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
<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
Re: compiller for c++/c
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.
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.
// Developing a yet unnamed microkernel in C++14.
-
- Member
- Posts: 283
- Joined: Mon Jan 03, 2011 6:58 pm
Re: compiller for c++/c
Shouldn't the destructor be called before the delete operator?Griwes wrote: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.Geri wrote:-delete translates to free, before, destructor must be called.
- Monk
- Griwes
- 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
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
<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