C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
CONVERT C TO CPP Posted by binnykt on 13 Oct 2008 at 11:01 AM

HI everyone I go tthis source code from the web & i would like to use it as a base for my minproject.Unfortunately it is written in c & I am required to have it in c++. Can anyone suggest tips for converting it into a cpp program?I have enclosed it as an attachment.

Thanks

P.S It is an old non standard code & will not work on most modern compilers

Attachment: MINIPROJECT.zip (2891 Bytes | downloaded 209 times)
Report
Re: CONVERT C TO CPP Posted by Lundin on 13 Oct 2008 at 11:55 AM
First of all, dos.h and graphics.h won't work on modern compilers as you say. Most of the code won't work on a standard C nor C++ compiler.

Apart from that, there are just minor things to correct, not much is different between the languages, and most
C++ compilers can compile C code (but with warnings). Here are some things I suggest:

- Remove the BOOLEAN typedef together with TRUE and FALSE, and use C++ bool instead.

- You need to use explicit typecasts in many cases, because C++ enforces stricter typecasts than C. For example, a C++ compiler might expect you to explicitly pass a "const char*" instead of a char* to a function etc. This is all part of good programming practice in C, so it should be there anyway.

The code also contains several serious bugs where if- and for statements lack {}.
Report
Re: CONVERT C TO CPP Posted by binnykt on 15 Oct 2008 at 9:39 AM
: First of all, dos.h and graphics.h won't work on modern compilers as
: you say. Most of the code won't work on a standard C nor C++
: compiler.
:
: Apart from that, there are just minor things to correct, not much is
: different between the languages, and most
: C++ compilers can compile C code (but with warnings). Here are some
: things I suggest:
:
: - Remove the BOOLEAN typedef together with TRUE and FALSE, and use
: C++ bool instead.
:
: - You need to use explicit typecasts in many cases, because C++
: enforces stricter typecasts than C. For example, a C++ compiler
: might expect you to explicitly pass a "const char*" instead of a
: char* to a function etc. This is all part of good programming
: practice in C, so it should be there anyway.
:
: The code also contains several serious bugs where if- and for
: statements lack {}.

Thanks Lundin
That is a good starting point for me.Now could you give me suggestions to implement classes in the above code.Thats the problem which was bugging me all the time.
P.S dont bother about the errors it runs perfectly well on my old compiler
Thanks a lot

Report
Re: CONVERT C TO CPP Posted by Lundin on 15 Oct 2008 at 10:40 AM
If you want proper object orientation you will have to rewrite the whole program from scratch. Use one class for each item you are drawing. Rectangle, text etc. Maybe one class for mouse handling, and so on.
Report
Re: CONVERT C TO CPP Posted by binnykt on 16 Oct 2008 at 10:13 AM
: If you want proper object orientation you will have to rewrite the
: whole program from scratch. Use one class for each item you are
: drawing. Rectangle, text etc. Maybe one class for mouse handling,
: and so on.
:

Okay will do that
Thanks




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.