How to code C in a C++ program?
Quite simply, anyone who thinks C is faster than C++, and anyone who thinks C++ is identical to C, both need to learn more about their programming language.
An algorithm written in C is faster than it's equivelent C++ version, IF AND ONLY IF, the C++ compiler is including extra, unneeded, things in the object file. Vice-versa, a C++ program is IDENTICAL to a C program, IF AND ONLY IF, the compiler does not include any extra C++ niceties in the particular case in question.
Such things do exist, an are relevant in some cases, such as extra constructor and destructor function calls. If a programmer translates a program which uses only built in types (no classes or structs) to C++ (meaning the simply compile it under a C++ compiler) then it will perform the same (assuming equal levels of compiler enginuity. If a person translates a struct oriented C program to C++, it MAY perform better or worse, depending on the presence of extra initialization and cleanup code. Such code exists in MOST nieve C++ programs, because programmers do not pay enough attention to pre-post conditions, and end up performing unnecessary zeroing of data, and checking of correctness. But that type of code, is usally a programmer issue (non-optimized programming ideas), not a language issue.
[edited by - Xai on March 17, 2003 2:44:49 PM]
An algorithm written in C is faster than it's equivelent C++ version, IF AND ONLY IF, the C++ compiler is including extra, unneeded, things in the object file. Vice-versa, a C++ program is IDENTICAL to a C program, IF AND ONLY IF, the compiler does not include any extra C++ niceties in the particular case in question.
Such things do exist, an are relevant in some cases, such as extra constructor and destructor function calls. If a programmer translates a program which uses only built in types (no classes or structs) to C++ (meaning the simply compile it under a C++ compiler) then it will perform the same (assuming equal levels of compiler enginuity. If a person translates a struct oriented C program to C++, it MAY perform better or worse, depending on the presence of extra initialization and cleanup code. Such code exists in MOST nieve C++ programs, because programmers do not pay enough attention to pre-post conditions, and end up performing unnecessary zeroing of data, and checking of correctness. But that type of code, is usally a programmer issue (non-optimized programming ideas), not a language issue.
[edited by - Xai on March 17, 2003 2:44:49 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement