View previous topic :: View next topic |
Author |
Message |
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Wed Sep 12, 2007 3:39 pm Post subject: The Mystic Art of C++ --> D porting |
|
|
This thread is simply a reminder to myself how to port C++ code to D code. Sometimes I forget, muck things up, then start all over again :-/
1. Copy the file.h into file.cpp, delete file.h and rename file.cpp to file.d
2. Put all the class functions inside the class
3. Replace all -> with .
4. Remove all #include's and #define's
5. func(Struct *) either maps to func(inout Struct) or func(Struct[])
- Pointers can either be ported to arrays or inout's, depending
6. Custom memory management code can be deleted
7. Only commit to SVN if there should be no problems with the .d port
8. Some static arrays --> dynamic arrays
9. Delete all 'const', except in constant value decl's
10. http://www.box2d.org/forum/viewtopic.php?f=3&t=16
11. Simply delete all const in function declarations, keep const in variable decls
12. MyClass *class --> MyClass class
oo. (more to come)
On updating to the latest box2D
1. Do a diff from the last box2D cpp source to see difference
2. Implement different in D code
3. Unless a really cool feature is added, only have to update once every few updates
Last edited by clayasaurus on Fri Feb 15, 2008 8:46 am; edited 3 times in total |
|
Back to top |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Mon Sep 17, 2007 3:05 am Post subject: |
|
|
Thanks !
A few suggestions and questions :
Questions:
Can you please add examples regarding 5)
How do you handle refernces ? : f.i.
Code: |
int intone;
int &rInt = intone;
|
How do you handle pointer to classes ? f.i.:
Code: |
class CFrame;
class CApp
{
public:
CFrame* m_WinMain;
}
|
Suggestions :
Add an entry on D Wiki ?
I think you can add : remove all forward referencing functions
Beside, I just have basic C++ know-how. So your message is allready a big win for me. (and I guess other people will participate too)
Bjoern |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Mon Sep 17, 2007 2:52 pm Post subject: |
|
|
I am by no means an expert in C++ porting and I probably won't find an error in any of the above unless it breaks but...
1) I'm not sure how to handle that reference, I think I'd need a better reference, because for that example, I'd say, use the actual variable itself and not the reference. I handle references / some pointers in functions with inout.
2) Class pointers. I've been doing ...
MrClass *class;
replace with
MrClass class;
Since I'm fairly sure all D classes are pointers to an object on the heap, the pointer is simply not necessary, and neither is inout for functions. |
|
Back to top |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Mon Sep 24, 2007 5:37 pm Post subject: |
|
|
I'll try to add something after the initial port is proven to work. |
|
Back to top |
|
|
|