I l@ve RuBoard Previous Section Next Section

28.7 Summary

What you must do to get C to compile with a C++ compiler:

  • Change K&R-style function headers into standard C++ headers.

  • Add prototypes.

  • Rename any functions or variables that are C++ keywords.

  • Change setjmp/longjmp calls into catch/throw operations.

Once you've done these tasks, you have a C+1/2 program. It works, but it's really a C program in C++'s clothing. To convert it to a real C++ program, you also need to do the following:

  • Change malloc to new.

  • Change free to delete or delete [] calls.

  • Turn printf and scanf calls into cout and cin.

  • When turning struct declarations into class variables, be careful of read, write, and memset functions that use the entire structure or class.

    I l@ve RuBoard Previous Section Next Section