But I'm wondering if this is the best tool to convert C programs to C+
+ programs.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Most C programs are also C++ programs themselves, except that some
identifiers (such as 'class', 'delete') may conflict with keywords.
C++ does not require its programs to use certain style (such as
object-oriented) or features (such as classes).
What does it mean to you to convert C programs to C++ programs,
and why would you want to do it?
--
Seungbeom Kim
> I want to convert C programs to C++ programs. I found this tool
> http://www.scriptol.com/scripts/ctocpp.php
>
> But I'm wondering if this is the best tool to convert C programs to C+
> + programs.
The best tool is a project team creating the C++ program from the
requirement specification. Especially a team knowing about OO design
and implementation.
Other tools probably result in a C program written in C++.
There is a famous saying:
"You can write FORTRAN in any language".
--
Greetings,
Jens Schmidt
Possibly once you are clear in your mind what you are trying to achieve.
Personally I would either leave the code alone (apart fgrom dealingf
with name/keyword clashes) or I would want to rework the code fgor myself.
Well, there is typically not much to "convert", however, a good C
program, even with the minor adaptations to be a valid C++ program,
makes still not a good C++ program. For example, while "malloc" is
certainly a valid C and C++ function to allocate memory, and while it
certainly works alike in C and C++, a good(!) C++ program would rather
allocate objects via "new" and not "malloc". In C++, you would need an
additional cast there (from void * to the target type), but that's it.
Thus, what are you trying to do?
So long,
Thomas
There a number of things that are different in C and C++ files,
including that the header files in C are not consistent when the
header files in C++.
I could use the instruction on the following page to compile C files
along with C++ files. But in one project, I feel that it might be
better to maintain only one languages (i.e., C++ files) rather than
two languages (i.e., both C and C++ files) if there is a way to
convert C files to C++ files.
http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html
--
> Peng Yu wrote:
>> I want to convert C programs to C++ programs.
>
> Most C programs are also C++ programs themselves, except that some
> identifiers (such as 'class', 'delete') may conflict with keywords.
> C++ does not require its programs to use certain style (such as
> object-oriented) or features (such as classes).
Most C programs using malloc() are not C++ programs because C++ lacks
the implicit conversion from void * to any pointer-to-object type. It
is possible to address this using templates and the preprocessor
(without actual code changes), but I suppose there are other gotchas.
--
> I want to convert C programs to C++ programs. I found this tool
> http://www.scriptol.com/scripts/ctocpp.php
>
> But I'm wondering if this is the best tool to convert C programs to C+
> + programs.
>
1) Adjust all of the standard headers by adding the character c to the
beginning and removing the .h at the end. For example:
#include <stdio.h> becomes #include <cstdio>
2) Check it compiles, adjust any miscellaneous problems.
--
Quote of the login:
It is easier to change the specification to fit the program than vice versa.
Ryan McCoskrie schrieb:
> 1) Adjust all of the standard headers by adding the character c to the
> beginning and removing the .h at the end. For example:
> #include <stdio.h> becomes #include <cstdio>
A lot of functions are in the std:: namespace in C++. They are not in C
for C does not have namespaces.
> 2) Check it compiles, adjust any miscellaneous problems.
Despite sounding easy, it can take a lot of time.
Frank
--
But they are accessible in the global namespace.
>
>> 2) Check it compiles, adjust any miscellaneous problems.
>
> Despite sounding easy, it can take a lot of time.
>
It depends how well written the C is. You may have problems if the
original has made use of the extras from c99 but well written C89 source
code compiles as C++ with very little change.
It is almost certainly better to leave good C code alone because turning
it into good idiomatic C++ is a major redesign problem. OTOH badly
written C is not worth reusing as C++ it needs a complete rewrite anyway.
#include <stdio.h>
is a perfectly valid C++ header, deliberately so. Companies such as
Adobe have ensured that their representatives on the INCITS C and C++
committees have ensured that it is possible to write source code that
compiles cleanly as both C and C++. They have spent time and money on
this because it matters to them.
Stavros K. Filippidis
http://stavros.filippidis.name
On Dec 20 2009, 10:11 am, Peng Yu <pengyu...@gmail.com> wrote:
> I want to convert C programs to C++ programs.
> I found this toolhttp://www.scriptol.com/scripts/ctocpp.php
>
> But I'm wondering if this is the best tool to convert C programs to
> C++ programs.
{ Please see the FAQ about top-posting. Edits: excessively long quoted lines
manually formatted, quoted banner removed. Please don't quote the banner. -mod }