FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The Mystic Art of C++ --> D porting

 
Post new topic   Reply to topic     Forum Index -> box2d4d
View previous topic :: View next topic  
Author Message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Wed Sep 12, 2007 3:39 pm    Post subject: The Mystic Art of C++ --> D porting Reply with quote

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
View user's profile Send private message AIM Address
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Mon Sep 17, 2007 3:05 am    Post subject: Reply with quote

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
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Sep 17, 2007 2:52 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Sun Sep 23, 2007 1:32 pm    Post subject: Reply with quote

http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx
Hi, (still) hoping that I am not picking on your nerves.
May be You'll share your experience with us.
Bjoern
Back to top
View user's profile Send private message
clayasaurus



Joined: 21 May 2004
Posts: 857

PostPosted: Mon Sep 24, 2007 5:37 pm    Post subject: Reply with quote

I'll try to add something after the initial port is proven to work.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> box2d4d All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group