Prev: goto
Next: Template: Specialization Help
From: Peng Yu on 20 Dec 2009 11:00 On Dec 20, 8:47 am, Seungbeom Kim <musip...(a)bawi.org> wrote: > 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). > > What does it mean to you to convert C programs to C++ programs, > and why would you want to do it? 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 -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Florian Weimer on 20 Dec 2009 11:01 * Seungbeom Kim: > 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. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Ryan McCoskrie on 20 Dec 2009 11:02 Peng Yu wrote: > 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. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Frank Birbacher on 23 Dec 2009 00:03 Hi! 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 -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Francis Glassborow on 23 Dec 2009 15:59
Frank Birbacher wrote: > Hi! > > 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. 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. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |